A simple implementation of multiple plug-ins in the drop-down box is more portable

Source: Internet
Author: User

I found a lot of problems when using the multi-first drop-down box I wrote last time. After modification and improvement, I have been able to use it well and it is more portable, the following is the source code.

Js
Copy codeThe Code is as follows:
(Function (){

$. Fn. extend ({
Checks_select: function (options ){
Jq_checks_select = null;
$ (This). val ("--- Select ---");
$ (This). next (). empty (); // empty first
$ (This). unbind ("click ");
$ (This). click (function (e ){
Jq_check = $ (this );
// Jq_check.attr ("class ","");
If (jq_checks_select = null ){
Jq_checks_select = jq_check.next ();
Jq_checks_select.addClass ("checks_div_select ");
// Jq_checks_select = $ ("<div class = 'checks _ div_select '> </div>"). insertAfter (jq_check );
$. Each (options, function (I, n ){
Check_div = $ ("<div> <input type = 'checkbox' value = '" + n + "'>" + n + "</div> "). appendTo (jq_checks_select );
Check_box = check_div.children ();
Check_box.click (function (e ){
// Jq_check.attr ("value", $ (this). attr ("value "));

Temp = "";
$ (This). parents (). find ("input: checked"). each (function (I ){
If (I = 0 ){
Temp = $ (this). val ();
} Else {
Temp + = "," + $ (this). val ();
}
});
// Alert (temp );
Jq_check.val (temp );
E. stopPropagation ();
});
});
Jq_checks_select.show ();
} Else {
Jq_checks_select.toggle ();

}
E. stopPropagation ();
});
$ (Document). click (function (){
Flag = $ ("# test_div ");
If (flag. val () = ""){
Flag. val ("--- Select ---");
}
Jq_checks_select.hide ();
});
// $ (This). blur (function (){
// Jq_checks_select.css ("visibility", "hidden ");
// Alert ();
//});
}
})

}) (JQuery );

Html
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript" src = "js/jquery. js">
</Script>
<Script type = "text/javascript" src = "js/jquery_mutili.js">
</Script>
<Script language = "javascript">
$ (Document). ready (function (){
Var options = {
1: "The first option ",
2: "The second option ",
3: "The third option ",
4: "fourth option ",
5: "fifth option ",
6: "sixth option"
};
$ ("# Test_div"). checks_select (options );
});
</Script>
<Style>
. Checks_div_select {
Width: 150px;
Background-color: # e9fbfb;
Border: 1px solid #18 cbcd;
Font-family: 'verdana ', '';
Font-size: 12px;
Position: absolute;
Left: 2px;
Top: 25px;
}
</Style>
</Head>
<Body>
<Div style = "position: relative;">
<Input type = "text" id = "test_div" readonly = "readonly"/>
<Div> </div>
</Div>
</Body>
</Html>

Related Article

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.