jQuery:悬停时扩展选择选项 [英] Jquery: Expanding select option on hover
本文介绍了jQuery:悬停时扩展选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在鼠标悬停时使用jquery展开/打开选择选项以显示选择列表中的所有项目?
How can i expand/open the select option on mouseover using jquery to show all the items in the select list?
<select size="3" id="something">
<option value="1">.1..</option>
<option value="2">.2..</option>
<option value="3">.3..</option>
</select>
推荐答案
您的意思是这样的.
$('select').hover(function(){
var count = $(this).children().length;
$(this).attr('size', count);
},function(){
$(this).removeAttr('size');
});
将鼠标悬停在选择上时,这将添加和删除size属性.参见此小提琴.
This will add and remove the size attribute when the select is hovered over. See this fiddle.
这篇关于jQuery:悬停时扩展选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文