Carl ManasterNimesh Madhavan提出了一个问题:Dropdownlist width in IE,或许与您遇到的问题类似。
回答者BalusC给出了该问题的处理方式:
Here's another jQuery based example. In contrary to all the other answers posted here, it takes all keyboard and mouse events into account, especially clicks:
if (!$.support.leadingWhitespace) { // if IE6/7/8 $('select.wide') .bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); }) .bind('click', function() { $(this).toggleClass('clicked'); }) .bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }}) .bind('blur', function() { $(this).removeClass('expand clicked'); }); }
Use it in combination with this piece of CSS:
select { width: 150px; /* Or whatever width you want. */ } select.expand { width: auto; }
All you need to do is to add the class wide
to the dropdown element(s) in question.
<select class="wide"> ... </select>
Here is a jsfiddle example. Hope this helps.
希望本文对你有帮助,欢迎支持JavaScript中文网
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/11113