Mouseover option of select for IE

落花浮王杯 提交于 2019-12-01 17:43:39

问题


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>

Thanks in advance


回答1:


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.

Example:

<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>



回答2:


What you are trying to do is not a standard web practice. I'm not saying its wrong, I can see why you'd want to do something like this. I think your answer is to not bother with the select control and try finding or designing a control that works with input elements instead and mimic what 'select' is doing. It wouldn't be that difficult and in the end you would probably have greater control and cross-browser capability.




回答3:


I would use a plugin of some kind (like this one) that is cross-browser compatible and manipulates ul's to look like a select dropdown.

Unfortunately IE dropped the ball on select elements and gives you little to no control of them.



来源:https://stackoverflow.com/questions/4292061/mouseover-option-of-select-for-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!