jQuery-對Radio/CheckBox的操做集合

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值this

$("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選擇器方面的知識要掌握紮實。spa

相關文章
相關標籤/搜索