jQuery-對Radio/CheckBox的操作集合

來源:互聯網
上載者:User

標籤:style   blog   http   os   io   使用   ar   art   div   

jQuery擷取Radio選擇的Value值

代碼 $("input[name=‘radio_name‘][checked]").val(); //選擇被選中Radio的Value值
 $("#text_id").focus(function(){//code...}); //事件 當對象text_id擷取焦點時觸發
 $("#text_id").blur(function(){//code...}); //事件 當對象text_id失去焦點時觸發
 $("#text_id").select(); //使文字框的Vlaue值成選中狀態
$("input[name=‘radio_name‘][value=‘要選中Radio的Value值‘").
attr("checked",true); //根據Value值設定Radio為選中狀態

jQuery擷取CheckBox選擇的Value值

$("input[name=‘checkbox_name‘][checked]"); //選擇被選中CheckBox元素的集合 如果你想得到
Value值你需要遍曆這個集合
$($("input[name=‘checkbox_name‘][checked]")).
each(function(){arrChk+=this.value + ‘,‘;});//遍曆被選中CheckBox元素的集合 得到Value值
$("#checkbox_id").attr("checked"); //擷取一個CheckBox的狀態(有沒有被選中,返回true/false)
$("#checkbox_id").attr("checked",true); //設定一個CheckBox的狀態為選中(checked=true)
$("#checkbox_id").attr("checked",false); //設定一個CheckBox的狀態為不選中(checked=false)
$("input[name=‘checkbox_name‘]").attr
("checked",$("#checkbox_id").attr("checked"));//根據3,4,5條,你可以分析分析這句代碼的意思
$("#text_id").val().split(","); //將Text的Value值以‘,‘分隔 返回一個數組

上面的這些操作,其實就是jQuery選取器的使用,希望大家對jQuery選取器方面的知識要掌握紮實。

jQuery-對Radio/CheckBox的操作集合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.