jQuery操作input值总结
来源:互联网 发布:数据同化 知乎 编辑:程序博客网 时间:2024/05/18 03:32
获取选中的值
获取一组radio被选中项的值
var item = $(“input[@name=items]:checked”).val();
获取select被选中项的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二个元素为当前选中值
$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中值
$('input[@name=items]').get(1).checked = true;
获取值:
文本框,文本区域:
$("#txt").attr("value");$("#txt").val();
多选框checkbox:
$("#checkbox_id").attr("value");
单选组radio:
$("input[@type=radio][@checked]").val();
下拉框select:
$('#sel').val();
控制表单元素:
文本框,文本区域:
$("#txt").attr("value",'');//清空内容$("#txt").attr("value",'11');//填充内容
多选框checkbox:
$("#chk1").attr("checked",'');//不打勾$("#chk2").attr("checked",true);//打勾if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组radio:
$("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
下拉框select:
$("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项$("<optionvalue='1'>1111</option><optionvalue='2'>2222</option>").appendTo("#sel")//添加下拉框的option$("#sel").empty();//清空下拉框
在Jquery中,用$("#id")来获得页面的input元素,其相当于document.getElementById("element")但是,该获取的是一个Jquery对象,而不是一个dom element对象.value是dom element对象的属性.所以,使用$("#id").value不能取到值取值的方法如下:
取值:
val = $("#id")[0].value;$("#id")[0].value = "new value";
赋值:
$("#id")[0].value = "new value";或者$("#id").val("new value");val = $("#id").attr("value");
- jQuery操作input值总结
- jquery操作input值总结
- jQuery操作input值总结
- jquery操作input值总结
- jquery操作input值总结
- jquery操作input值总结
- jQuery操作input值总结
- jQuery操作input值总结
- jQuery操作input值总结
- jQuery操作input值总结
- jQuery操作input值的各种方法总结
- jQuery操作input值的各种方法总结
- jQuery操作input改变value属性值
- jQuery操作input
- jQuery操作input
- jQuery操作input
- jQuery操作input
- jquery操作常用input
- android in practice_framework
- 搞定数组查询一个却显示8个错误
- 联想a668t各种root方法汇集
- js验证 手机或固话
- 程序员提升资料
- jQuery操作input值总结
- iPhone/iPod Touch: application executable is missing a required architecture. At least one of the fo
- 使用POI导入Excel数据到系统
- Arcgis FlexViewer 说明
- The culture of Statistic Learning
- Dijkstra算法求最短路径(java)
- px,in,mm,pt,dp,dip,sp解释及转换
- IP地址正确性校验
- 九月十月百度人搜,阿里巴巴,腾讯华为笔试面试八十题(第331-410题)