Home > Web Front-end > JS Tutorial > body text

A simple plug-in that implements multiple selections in a drop-down box is more portable_jquery

WBOY
Release: 2016-05-16 16:49:59
Original
914 people have browsed it

When using the multiple-first drop-down box I wrote last time, I found a lot of problems. After modification and improvement, it can now be used well and has good portability. The following is the source code.

js

Copy code The code is as follows:

(function(){

$.fn.extend({
checks_select: function(options){
jq_checks_select = null;
$(this).val("---Please 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 = $("
").insertAfter(jq_check);
$ .each(options, function(i, n){
check_div=$("
" n "
" ).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("---Please select---" );
}
jq_checks_select.hide();
});
//$(this).blur(function(){
//jq_checks_select.css("visibility", "hidden");
//alert();
//});
}
})

})(jQuery);

html
Copy code The code is as follows:


< head>













A simple plug-in that implements multiple selections in a drop-down box is more portable_jquery
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!