jQuery-选择列表选项悬停 [英] jQuery-Select list option hover

查看:70
本文介绍了jQuery-选择列表选项悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当鼠标光标悬停在某个选项上时,我想提醒该选项.我使用以下代码:

I want to alert an option when the mouse-cursor is over it. I use this code:

$("select > option").hover(function ()
    { 
        alert($(this).attr("id"));
    });

不幸的是,这在IE和FF中均不起作用.

Unfortunately, this is neither working in IE nor in FF.

有人可以给我一个提示吗?

Can someone give me a hint please?

推荐答案

您可以尝试一下.

$("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
     }
});

这篇关于jQuery-选择列表选项悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆