Write your own Easyui checkbox.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.