jQuery选择列表选项悬停
我想在鼠标光标位于某个选项上时发出警告。我使用以下代码:jQuery选择列表选项悬停,jquery,Jquery,我想在鼠标光标位于某个选项上时发出警告。我使用以下代码: $("select > option").hover(function () { alert($(this).attr("id")); }); 不幸的是,这在IE和FF中都不起作用 谁能给我一个提示吗?你可以试试这个 $("select").hover(function (e) { var $target = $(e.target); if($target.is('optio
$("select > option").hover(function ()
{
alert($(this).attr("id"));
});
不幸的是,这在IE和FF中都不起作用
谁能给我一个提示吗?你可以试试这个
$("select").hover(function (e)
{
var $target = $(e.target);
if($target.is('option')){
alert($target.attr("id"));//Will alert id if it has id attribute
alert($target.text());//Will alert the text of the option
alert($target.val());//Will alert the value of the option
}
});
如果通过添加size=x属性创建列表框类型选择框,如下所示:
<select size="3">
<option>...</option>
<option>...</option>
</select>
我想这是一个相当不错的解决办法- 使用mouseover事件将选择框的大小设置为其子项的数量 使用mouseenter事件获取选项。当大小属性存在时,mouseenter可以完美地处理选项,我们现在都知道这一点 使用mouseout事件将选择框的大小设置回1,以恢复正常的选择框:
检查下面的链接,有用的信息还有一个原因是Chrome和IE不允许您直接在选项元素上捕获事件,但允许您在选定元素上捕获事件;我只是在选项中看不到mouseover或hoever事件,只是选择。似乎在Chrome和FF中工作,但在IE.jQuery+id.closest.t-palette.findselect.hoverfunction事件{T5.console.debughover+this.id;var$target=jQueryevent.target;if$target.isoption{T5.console.debugoption=+$target.text;this.title=$target.text;} };这对我不起作用。。我正在尝试相同的代码。当我将鼠标悬停在选项上时,它不会发出警报。在safari和chrome中测试工作-没有测试IE-很好,现在删除大小并在chrome@A上再次测试_funs@TarunIdk什么是你的牛肉在这里,我的回答说,你需要包括这个工作的大小属性,当你这样做-它的工作。。。
$('option').hover(function(){
//code here
});