对不起,英语不好。如果用户更改选择框或仅将鼠标悬停在单个事件上,如何获取选择框的价值。我已经尝试过这个但是它不起作用

jQuery("select[name*=super_attribute]").on('change , hover', function(){
 alert('trigger');
});


我知道我们可以这样做,使功能分开

jQuery("select[name*=super_attribute]").on('change', function(){
 alert('trigger');
});




jQuery("select[name*=super_attribute]").on('hover', function(){
 alert('trigger');
});


但是我想不单独处理单个事件,因为在两种情况下我都将执行相同的功能。

最佳答案

事件列表中不需要逗号,当您必须对多个选择器应用任何操作时使用逗号

jQuery("select[name*=super_attribute]").on('change mouseover', function(){
  alert('trigger');
});


如果必须选择多个元素,则可以这样使用逗号

jQuery("select[name*=super_attribute],#xyz").on('change mouseover', function(){
      alert('trigger');
    });

关于javascript - 在悬停时获取选择框的值或在同一事件中进行更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39847529/

10-12 00:05
查看更多