现在的位置: 首页 > 综合 > 正文

jquery获取和设置radio,check,select选项

2013年12月11日 ⁄ 综合 ⁄ 共 1263字 ⁄ 字号 评论关闭

select控件选项

1,获取select选中的value值

      $("#selectID").val();

2,获取select选中的text的值

 $("#selectID").find("option:selected").text()

3,设置select的第几项为当前选中项

$("#selectID").attr("value",2);//设置第二项为当前选中项

4,添加option

$("selectID").append("<option value='5'>select5</option>");

5,删除一项option

$("#SelectID option[value='3']").remove();  //删除Select中Value='3'的Option

6.,获取Select选择的索引值 

var checkIndex=$("#selectID ").get(0).selectedIndex;  //获取Select选择的索引值 

7,删除所有项

$("#SelectID").remove();

 

checkbox控件的使用

1,获取checkbox的value

$("#checkboxID").value或$("input[type='checkbox']").eq(n).attr("checked").value

2,设置选中项

$("input[type='checkbox']").eq(1).attr("checked")//设置第一个checkbox为选中的项

3,删除所有checkbox

  $("input[type='checkbox']").remove()

4,checkbox方法

  $(document).ready(function() {
        var check = $("input[type='checkbox']");
        check.each(function(n) {
        check.eq(n).bind("click", function() {
          
                if (check.eq(n).attr("checked") != false) {
                    var value = check.eq(n).val();
                    alert(value);
                }
                else {
                    alert(check.eq(n).attr("checked"));
                }
            })
        });
    });

radio控件

1,获取选中的value值

$("input[type='radio']:checked").val();

2,设置指定的项为当前选中项

  $("input[type='radio']").eq(1).attr("checked",true);//设置第二项为选中项

抱歉!评论已关闭.