javascript - jQuery idSelector.bind() 方法不能正常工作

标签 javascript jquery css styles

我想用鼠标悬停事件绑定(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/

相关文章:

javascript - 如何强制下拉菜单在 IE 11 上向下移动?

javascript - 从方法返回全局变量

javascript - 使用内部变量的 jQuery 自定义插件之间的冲突

javascript - 计算一个 DIV 中有多少个字符

javascript - 使用 jquery 进行日期格式验证

css - font-face 不显示在 Firefox 上

javascript - 使用 async/await 时,Firebase Cloud Firestore 查询返回 Promise { <pending> } 而不是 fulfilled

javascript - 影响多个相同元素并避免不在 DOM 中时发生 null 错误,纯 JavaScript 与 jQuery

javascript - 无法禁用 twitter bootstrap 下拉项

html - 为什么我使用 Bootstrap 的代码不会在缩略图行之间添加水平空间?