Pap*_*ppu 5 jquery select mouseover
我正在使用IE7.当鼠标悬停在选项上时,我想在页面中显示选择框中每个选项的描述.因此,当我开始编写代码时,当鼠标悬停在选项上时,该代码会在文本框中显示选项值.但它永远不会奏效.它就像一个改变事件.
<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>
Run Code Online (Sandbox Code Playgroud)
提前致谢
如果您希望描述显示在mouseover上,而不是更改上,我认为最好使用工具提示。这可以通过 HTML 的属性来完成title,不需要 JS。
例子:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4327 次 |
| 最近记录: |