简体   繁体   English

为什么onmouseout会在select标签内调用每个选项更改

[英]Why onmouseout called every option change while inside select tag

The multiple select option call onmouseout function for every option change without come out from select box, May I know the reason for this event issue? 对于每个选项更改,多选择选项将调用onmouseout函数,而不会从选择框中出现,我是否可以知道此事件的原因?

Bug fixed while remove the multiple attribute from the select tag. 错误修复,同时从select标记中删除了multiple属性。

 function mout(e){ console.log("mouse is out"); } 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <select id="x" multiple onmouseout="mout(this)"> <option value="1">11:00 10-10-2017</option> <option value="2">11:00 10-10-2017</option> <option value="3">13:00 10-10-2017</option> </select> 

Use mouseleave . 使用mouseleave

The mouseout event triggers when the mouse pointer leaves any child elements as well the selected element. 当鼠标指针离开任何子元素以及所选元素时,将触发mouseout事件。

The mouseleave event is only triggered when the mouse pointer leaves the selected element. 仅当鼠标指针离开所选元素时才触发mouseleave事件。

 function mout(e){ console.log("mouse is out"); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <select id="x" multiple onmouseleave="mout(this)"> <option value="1">11:00 10-10-2017</option> <option value="2">11:00 10-10-2017</option> <option value="3">13:00 10-10-2017</option> </select> 

On mouseout is similar to onfocusout; 在mouseout上类似于onfocusout。 when select has multiple enabled the UI is such that onmouseout = onfocusout = onhover; 当select启用了multiple ,UI如下所示:onmouseout = onfocusout = onhover;

Same not in multiple disabled during which we have a traditional dropdown wherein onmouseout is triggered after clicking, changing and then focusing out . multiple禁用不同,在传统的下拉菜单中, clicking, changing and then focusing out后会触发onmouseout,这与multiple禁用功能不同。

Hope this helps. 希望这可以帮助。

You can be used mouseleave on jQuery. 您可以在jQuery上使用mouseleave

 $( "#x" ).on( "mouseleave", function(e) { console.log("mouse is out"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> <select id="x" multiple> <option value="1">11:00 10-10-2017</option> <option value="2">11:00 10-10-2017</option> <option value="3">13:00 10-10-2017</option> </select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM