1 js中:$("#allCheck").change(function(){
var flag = $(this).attr("checked");
$('#delForm input[type="checkbox"]').each(function () {
$(this).attr('checked',flag)})
});
2 jsp中:<th scope="col" class="borl_no"><input id="allCheck" type="checkbox" name="" value="" /></th>
3 有時候在頁面中有多處checkbox,所以根據id來區別,這時需要根據id來控制全選的區域:$('#checkid').click(function(){
var list = $('[id=check]').length;
if($('#checkid').attr("checked")==true){
for(var i = 0 ; i < list ; i ++){
$('[id=check]').attr("checked","true");
}
}else if($('#checkid').attr("checked")==false){
$('[id=check]').click();
}
});
等同于
$("#checkid").change(function(){
var flag = $(this).attr("checked");
$('[id=check]').each(function () {
$(this).attr('checked',flag)})
});
4 是否選擇checkbox判斷:function del(){
var num=0;
$('input[type="checkbox"]').each(function () {
if ($(this).attr('checked')) {
num++;
}
});
if(num==0){
alert("請選擇刪除對象!");
return;
}
if(confirm("您確定要刪除選中的項目么?")){
document.getElementById("delForm").action="/html/com/deleteCallMarketContactAction.do";
document.getElementById("delForm").submit();
}
}
posted on 2012-07-09 15:45
canry Tong 閱讀(240)
評論(0) 編輯 收藏 所屬分類:
jsp