123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- $(function(){
- //var list=[
- // { Id: 1, Desc: "小猫", IsChecked:true},
- // { Id: 2, Desc: "小狗", IsChecked:true},
- // { Id: 3, Desc: "小兔子", IsChecked:false},
- // { Id: 4, Desc: "小乌龟", IsChecked:false},
- // { Id: 5, Desc: "大西瓜", IsChecked:false},
- // { Id: 6, Desc: "黄河", IsChecked:false},
- // { Id: 7, Desc: "长江", IsChecked:true},
- // { Id: 8, Desc: "天安门", IsChecked:false},
- // { Id: 9, Desc: "神仙", IsChecked:false},
- // { Id: 10, Desc: "小鬼", IsChecked:false},
- //];
- //initCheckbox(list);
-
-
- })
- function initCheckbox(idKey, list) {
- if(list.length>0){
- //$('#' + idKey).prepend('<div class="choose"><button class="mybtn" id="all">全选</button><button class="mybtn" id="anti">反选</button></div><div id="checkList"></div>');
- $('#' + idKey).prepend('<div id="checkList"></div>');
- $('#' + idKey +' #all').click(function(){
- $('#' + idKey +' #checkList').find('input[type=checkbox]').prop('checked',true);
- });
- $('#' + idKey +' #anti').click(function(){
- var checklist = $('#' + idKey +' #checkList').find('input[type=checkbox]');
- checklist.each(function(index,item){
- if(checklist.eq(index).is(":checked")){
- checklist.eq(index).prop('checked',false);
- }else{
- checklist.eq(index).prop('checked',true);
- }
- })
- });
- list.map(function(item){
- if (item.IsChecked){
- $('#' + idKey+' #checkList').append('<label><input type="checkbox" checked=true id="'+item.Id+'"/>'+item.Desc+'</label>');
- }else{
- $('#' + idKey+' #checkList').append('<label><input type="checkbox" id="' + item.Id + '"/>' + item.Desc+'</label>');
- }
- })
- }
-
- }
- function initAndCreateCheckbox(idKey, list) {
- if (list.length > 0) {
- var content = "<div id= '" + idKey + "' class='mycheckbox'>";
- content += '<div id="checkList">';
- list.map(function (item) {
- if (item.IsChecked) {
- content += '<label><input type="checkbox" checked=true id="' + item.Id + '"/>' + item.Desc + '</label>';
- } else {
- content += '<label><input type="checkbox" id="' + item.Id + '"/>' + item.Desc + '</label>';
- }
- })
- content += "</div></div>";
- return content;
- }
- }
- function getChecked(){
- var checkboxs=$('#checkList').find('input[type=checkbox]');
- var checkedID=[];
- for(var i=0;i<checkboxs.length;i++){
- var current=checkboxs.eq(i);
- if(current.is(':checked')){
- checkedID.push(current.attr('id'));
- }
- }
- return checkedID;
- }
- function getChecked2(ctr) {
- var checkboxs = $('#' + ctr+' #checkList').find('input[type=checkbox]');
- var checkedID = [];
- for (var i = 0; i < checkboxs.length; i++) {
- var current = checkboxs.eq(i);
- if (current.is(':checked')) {
- checkedID.push(current.attr('id'));
- }
- }
- return checkedID;
- }
|