Select
jQuery获取Select选择的Text和Value:
1 | 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 |
jQuery设置Select选择的Text和Value:
1 | 1. $("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中 |
jQuery添加/删除Select的Option项:
1 | 1. $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项) |
Checkbox
全选/取消
jQuery.attr 获取/设置对象的属性值,如:
1 | $("input[name='chk_list']").attr("checked"); //读取所有name为'chk_list'对象的状态(是否选中) |
下面的代码是获取上面实例中选中的checkbox的value值:
1 | $(document).ready(function() { |
获取checkbox的value
1 | $("#checkboxID").value或$("input[type='checkbox']").eq(n).attr("checked").value |
设置选中项
1 | $("input[type='checkbox']").eq(1).attr("checked")//设置第一个checkbox为选中的项 |
删除所有checkbox
1 | $("input[type='checkbox']").remove() |
checkbox方法
1 | $(document).ready(function() { |
radio
获取选中的value值
1 | $("input[type='radio']:checked").val(); |
设置指定的项为当前选中项
1 | $("input[type='radio']").eq(1).attr("checked", true);//设置第二项为选中项 |
解决多个Radio
$("input[type='radio'][@name='rdoTest2']").eq(0).attr("checked", true);