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>