Can I open a dropdownlist using jQuery

后端 未结 14 1445
终归单人心
终归单人心 2020-11-22 09:49

For this dropdownlist in HTML:


I would lik

14条回答
  •  清酒与你
    2020-11-22 09:52

    This is spruced up from the answers just above and uses the length/number of options to conform to how many options there actually are.

    Hope this helps somebody get the results they need!

        function openDropdown(elementId) {
            function down() {
                var pos = $(this).offset(); // remember position
                var len = $(this).find("option").length;
                    if(len > 20) {
                        len = 20;
                    }
    
                $(this).css("position", "absolute");
                $(this).css("zIndex", 9999);
                $(this).offset(pos);   // reset position
                $(this).attr("size", len); // open dropdown
                $(this).unbind("focus", down);
                $(this).focus();
            }
            function up() {
                $(this).css("position", "static");
                $(this).attr("size", "1");  // close dropdown
                $(this).unbind("change", up);
                $(this).focus();
            }
            $("#" + elementId).focus(down).blur(up).focus();
        }
    

提交回复
热议问题