jquery擷取和設定radio,check,select選項

來源:互聯網
上載者:User

標籤:style   blog   使用   io   strong   art   ar   cti   

 

  

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);//設定第二項為選中項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.