Recently the project has used the framework of Easyui, found a circle and did not find the CheckBox list control, forced only to implement their own, in order to facilitate the reuse, their own encapsulation of the next, there is need, directly take to use it. If you have any comments or suggestions, please advise me.
Invoke Example
<HTML><Head> <title></title> <MetaCharSet= ' UTF8 '> <Scripttype= "Text/javascript"src= "Jquery.min.js"></Script> <Scripttype= "Text/javascript"src= "Jquery.checkbox.js"></Script></Head><Body> <Divclass= ' Easyui-checkbox 'ID= ' Test '> </Div> <DivID= ' ShowValues '></Div> <Div> <inputtype= ' button 'ID= ' Btngetvalue 'value= ' Get checked value '> </Div> <Scripttype= "Text/javascript">$ (). Ready (functionfunction_name (argument) {//Initialize the value of the pass /*$ (' #test '). CheckBox ({data:[{text: ' Sunday ', Value: ' 1 '}, {text: ' Monday ', Value: ' 2 '}, {text: ' Week Two ', Value: ' 3 '}]});*/ //Initialize $('#test'). checkbox (); //SetValue Setting a checkbox entry $('#test'). CheckBox ('SetValue', [{text:'Sunday', Value:'1'}, {text:'Monday', Value:'2'}, {text:'Tuesday', Value:'3'} ]); //checked Setting the default check $('#test'). CheckBox ('checked',['2']); $('#btnGetValue'). On ('Click',function(){ //GetValue Gets the value of the selected checkbox item varchecked=$('#test'). CheckBox ('GetValue'); $('#showValues'). HTML ("'); $('#showValues'). HTML (Checked.join (',')); }); }); </Script></Body></HTML>
Realize source code Jquery.checkbox.js
(function($){ functionCreatebox (me,options) {if(options.data) {$.each (Options.data,function(Index,item) {me.append (' <input type= ' checkbox "value=" ' +item.value+ ' "/> ' +item.text); }); Registerevent (Me); } } functionregisterevent (Me) {$ (Me). Children (). On (' Click ',function(){ if($( This). attr (' checked ')){ $( This). Removeattr (' checked '); }Else{ $( This). attr (' checked ', ' checked '); } }); } $.fn.checkbox=function(options, param) {if(typeofOptions = = ' String '){ varMETHOD =$.fn.checkbox.methods[options]; if(method) {returnMethod This, param); } Else { return This. Combo (options, param); }} Options= Options | | {}; Createbox ( This, Options); }; $.fn.checkbox.methods={setValue:function(Me,para) {me.html (); Createbox (Me,{data:para}); }, GetValue:function(Me,para) {varvalues=NewArray (); $ (Me). Children (). each (function(index,item) {if($ (item). attr (' checked ') = = ' checked ') {Values.push (item). attr (' Value ')); } }); returnvalues; }, checked:function(Me,para) {$ (Me). Children (). each (function(index,item) {if(Para.indexof (item). attr (' value ')) >-1){ if($ (item). attr (' checked ')! = ' checked ') {$ (item). click (); } } }); } };}) (jQuery);
Write your own Easyui checkbox.