悬停时,我想调用一个函数。如果元素具有类"disabled_btn",则应将其压制。为什么模式代码不起作用?斯菲德尔
.html
<button id="btn" > hover here</button>
.JS
$('#btn:not(.disabled-btn)').on('hover', function(){
alert('click');
});
尝试mouseover
而不是hover
:
$('#btn:not(.disabled-btn)').on(' mouseover', function () {
alert('click');
});
演示:http://jsfiddle.net/qa7co8y4/2/
你应该使用.hover()
而不是on("hover")
。喜欢这个:
$('#btn:not(.disabled-btn)').hover(function() {
alert('click');
});
小提琴:http://jsfiddle.net/qa7co8y4/3/
在
JS 上没有什么比hover
更需要改用mouseenter
或mouseover
了。
$('#btn:not(.disabled-btn)').on(' mouseenter', function () {
alert('click');
});
或
$('#btn:not(.disabled-btn)').on(' mouseover', function () {
alert('click');
});
我更新你的代码,你会看到更新的代码
$('#btn:not(.disabled-btn)').hover(function(){
alert('click');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn" class=""> hover here</button>