DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jquery數組之存放checkbox全選值示例代碼
jquery數組之存放checkbox全選值示例代碼
編輯:JQuery特效代碼     
. 代碼如下:
<input type="checkbox" id="checkAll" value="1">全選/全部不選
<input type="checkbox" name="items" value="1">1
<input type="checkbox" name="items" value="2">2
<input type="checkbox" name="items" value="3">3
<input type="checkbox" name="items" value="4">4
<input type="checkbox" name="items" value="5">
<input type="button" onclick="show()" value="提示選擇的">
<script>
$("#chekcAll").click(function(){
if(this.checked){
$("input[name=items]").attr("checked","checked");
}
else{
$("input[name=items]").attr("checked",null);
}
})
function show(){
var strIds=new Array();//聲明一個存放id的數組
$("input[name=items]").each(function (i,d){
if (d.checked) {
strIds.push(d.value);
}
})
if(strIds.length<1)
alert("您沒有選中項!");
else{
var ids=strIds.join(",");
alert("你選中的字符串有:"+ids);
}


}

</script>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved