抱歉英语不好。如果用户更改选择框或仅将鼠标悬停在带有单个事件的选择框上,如何获取选择框的值。我已经尝试过这个,但它不起作用
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/