我想在鼠标光标悬停时提醒选项.我用这个代码:
$("select > option").hover(function ()
{
alert($(this).attr("id"));
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,这既不适用于IE,也不适用于FF.
有人可以给我一个提示吗?
Sha*_*oli 20
你可以试试这个.
$("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
}
});
Run Code Online (Sandbox Code Playgroud)
如果您通过添加“size = x”属性来制作“列表框”类型的选择框,如下所示:
<select size="3">
<option>...</option>
<option>...</option>
</select>
Run Code Online (Sandbox Code Playgroud)
悬停事件将作用于选项元素:
$('option').hover(function(){
//code here
});
Run Code Online (Sandbox Code Playgroud)