飞龙博客

妙法莲华经

全选反选飞龙jQuery解决方案

feilong.org 修订于2012-03-06 04:16:17 283 次浏览

记得用JavaScript写的全选反选飞龙jQuery解决方案吗?今晚飞龙用jQuery试试checkbox列表的全选反选解决方案。本日志修订网址:http://feilong.org/check-uncheck-juery-solution 2012年于广州

//全选反选飞龙jQuery解决方案
$(function(){

//反选方案
function fl_checkbox(formid,submitclassname){
$('#'+formid+' .checkrevert').click(function(){
$('#'+formid+' input[type=checkbox]').each(function(i){//1
if(this.checked){
$(this).removeAttr('checked');//alert('checked');
//$(this).prop("checked", false);for jQuery 1.6+
}else{
$(this).attr('checked', 'checked');//alert('no')
//$(this).prop("checked", true);//for jQuery 1.6+
}
});
});//1

//全选方案
$('#'+formid+' .checkall').click(function(){
$('#'+formid+' input[type=checkbox]').attr('checked', 'checked');
});//1

//某表单提交
$('.'+submitclassname).click(function(){
var checkedlength=$('#'+formid+' input[type=checkbox]:checked').length;//alert(checkedlength);
if(checkedlength){return true;
//$('#'+formid).submit(function(){return true;});	
}else{alert('至少选一项');return false;// so it won't submit		
} 
});//1


}///function over

//applications
fl_checkbox('goodorder','ordersubmit');
fl_checkbox('catbuy','buysubmit');



});//0




/**以下只是参考资料**/
//var checked=$('input[name=foo]').attr('checked');alert(checked);
//var checked=$("#list input[type='checkbox']:checked"); //alert(checked.length);
//var checked=$('#list input:checkbox:checked');alert(checked.length);
//var ischecked=$(this).is(':checked'); //alert(ischecked);
var firstchecked=$('#list input:checkbox:checked').first();alert(firstchecked.val());
var checked=$("#list input:checked[name='jiluids[]']");alert(checked.length);

//http://feilong.org/check-uncheck-juery-solution

//var nochecked=$("input[type='checkbox']").not(':checked');alert(nochecked.length);
//var disabled=$("input[disabled='disabled']");//alert(haschecked.length);

var checked=$(this).attr('checked');
if(checked){
alert(checked);$('input[name=foo]').attr('checked', true);
}else{
alert(checked);	$('input[name=foo]').attr('checked', false);
//$('input[name=foo]').removeAttr('checked')
if($('input[name=' + newData + ']').is(":checked")){}
}//feilong.org

//$('#inboxx input').attr('checked', true);
//$('#inboxx input[type=checkbox]').attr('checked', true);

//$('input[name=bar]').attr('checked', 'checked'); // for check
//$('input[name=bar]').removeAttr('checked'); // for uncheck

//var checked=$('#list input:checkbox:checked');alert(checked.length);

$('input:checked');
//http://widowmaker.kiev.ua/checkbox/
//http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery-or-javascript
//http://api.jquery.com/checked-selector/
//http://api.jquery.com/prop/#prop1
//$('#inboxx input').attr('checked', true);
//$('#inboxx input[type=checkbox]').attr('checked', true);

//$('input[name=bar]').attr('checked', 'checked'); // for check
//$('input[name=bar]').removeAttr('checked'); // for uncheck

//var checked=$('#list input:checkbox:checked');alert(checked.length);

$('input:checked');


//$("#list").submit(function(){return false;});// so it won't submit

$(".myCheckbox").prop("checked", true);
$(".myCheckbox").prop("checked", false);

如果只想用JavaScript,可以参考:http://feilong.org/checkbox-choose-all-atleast-one-checked

更新网址:https://feilong.org/check-uncheck-juery-solution
最初发布:20120306 04:16:17 feilong.org 于广州

加入收藏夹,查看更方便。

所在分类: 网站开发

新作:

旧文: