IE选择的鼠标悬停选项 [英] Mouseover option of select for IE

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

问题描述

我正在使用IE7.当鼠标悬停在选项上方时,我希望在页面上为选择框中的每个选项显示说明.因此,在开始时,我编写了当鼠标悬停在选项上方时在文本框中显示选项值的代码.但它永远都行不通.它就像更改事件一样工作.

I'm using IE7. I want to have show a description in the page for each option in the select box when the mouse is over the option. So as starting I wrote the code which shows the option value in the text box when mouse is over an option. But it never works. It works as if a change event.

<input name="selectedValue" id="selectedValue" >
<select id="TestCombo" name="TestCombo" >
     <option value="0" selected="selected">Zero</option>    
 <option value="1">One</option>
 <option value="2">Two</option>
 <option value="3">Three</option>
</select>

<script type="text/javascript">
$( function() {
    $('#TestCombo option').mouseover( function() {
          $('#selectedValue').val($('#TestCombo option:selected').val());
    });
});
</script>

预先感谢

推荐答案

如果您希望说明显示在鼠标悬停而不是更改上,我认为这会更好使用工具提示.可以使用HTML的title属性来完成,不需要JS.

If you want the description to show up on mouseover, not on change, I think it's better to use tooltips. That can be done with HTML's title attribute, no JS needed.

示例:

<input name="selectedValue" id="selectedValue">
<select id="TestCombo" name="TestCombo" >
  <option title="Nothing." value="0" selected="selected">Zero</option>    
  <option title="The smallest number that has a meaning." value="1">One</option>
  <option title="Look, another small number!" value="2">Two</option>
  <option title="RGB - Red-Green-Blue. That's three colors!" value="3">Three</option>
</select>

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

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