我想用鼠标悬停事件绑定(bind)一个按钮。当我将鼠标悬停在按钮上时,样式正在执行它的一部分,但在鼠标移出时,更改的样式不会删除。
<script>
$(document).ready(function () {
$('#btnSubmit').bind('mouseover mouseout', function (event) {
if (event.type = 'mouseover') {
$(this).addClass('ButtonStyle');
}
else {
$(this).removeClass('ButtonStyle');
}
});
});
</script>
<style>
.ButtonStyle
{
background-color:red;
font-weight: bold;
color: white;
cursor: pointer;
}
</style>
最佳答案
这是因为你需要我们的鼠标离开功能
尝试这样的事情
代码:
$('#btnSubmit').bind('mouseover', function (event) {
$(this).addClass('ButtonStyle');
})
.bind('mouseleave',function(){
$(this).removeClass('ButtonStyle');
});
如果有帮助请告诉我
关于javascript - jQuery idSelector.bind() 方法不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51152608/