仅对于 Internet Explorer,似乎元素上的单击、mousedowns、mouseups、mouseovers 等的目标 (srcElement)<select />不会与<option />元素绑定。
给定以下 HTML:
<select id="madness">
<option value="1">One</option>
<option value="2">Two</option>
<option value="2">Three</option>
</select>
和这个基本的 jQuery 事件处理程序:
$("#madness").mousedown(function(e){
alert(e.target.value); //jQuery pushes srcElement into the target for us here
});
位于e.target或e.srcElement始终等于<select />而不是 的对象<option />。
我决定发挥创意并尝试使用document.elementFromPoint(e.clientX,e.clientY)它也返回 SELECT 元素。
这就带来了一个问题,有没有办法通过事件参数、坐标或其他任何东西来确定<option />内部?<select />我知道我可以用复选框的可滚动 div 来伪造它。出于这个问题的目的,我想要任何可以使用本机选择元素的解决方案。