飞龙博客

飞龙博客 飞龙在天

全选反选飞龙jQuery解决方案

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

记得用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 于广州

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

所在分类: 网站开发

新作:

旧文:

blog money bui 教程 echarts 教程 eclipse 教程 html css 教程 IT趋势 js 教程 json 教程 mysql 教程 nodejs npm 教程 onblog SQLite 教程 tutorials vscode 教程 wap网站 winpe启动盘 wordpress 主机推荐 书法 前端开发 博客 名企名网 国学 域名注册 常用软件 建站程序 操作系统 教程 数码 无线上网 日记 电子商务 电脑笔记本 网站 网站优化 网站开发 网站推广 网站策划 网络 虚拟现实 默认