Javascript jQuery idSelector.bind()方法无法正常工作
我想用鼠标悬停事件绑定一个按钮。当我将鼠标悬停在按钮上时,样式正在执行它的部分操作,但在mouseout上,更改的样式不会删除Javascript jQuery idSelector.bind()方法无法正常工作,javascript,jquery,css,styles,Javascript,Jquery,Css,Styles,我想用鼠标悬停事件绑定一个按钮。当我将鼠标悬停在按钮上时,样式正在执行它的部分操作,但在mouseout上,更改的样式不会删除 <script> $(document).ready(function () { $('#btnSubmit').bind('mouseover mouseout', function (event) { if (event.type = 'mouseover') {
<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>
$(文档).ready(函数(){
$('#btnSubmit').bind('mouseover mouseout',函数(事件){
if(event.type='mouseover'){
$(this.addClass('ButtonStyle');
}
否则{
$(this.removeClass('ButtonStyle');
}
});
});
.钮扣样式
{
背景色:红色;
字体大小:粗体;
颜色:白色;
光标:指针;
}
这是因为您需要使用鼠标离开功能
试试这样的
代码:
如果有帮助,请告诉我这是因为您需要我们的鼠标离开功能 试试这样的 代码:
如果有帮助,请告诉我。您只需使用css即可完成:
.btn:悬停{
背景色:红色;
字体大小:粗体;
颜色:白色;
光标:指针;
}
尝试将鼠标悬停在我身上
您只需使用css执行即可:
.btn:悬停{
背景色:红色;
字体大小:粗体;
颜色:白色;
光标:指针;
}
try hover me
您能告诉我如何将此样式类用于页面中的所有按钮使用公共类用于按钮,例如“btn hover common”,并将上面代码中的“btnSubmit”替换为“.btn hover common”。然后它将适用于每个按钮。您能告诉我如何将此样式类用于页面中的所有按钮使用公共类用于按钮,例如“btn hover common”,并将上述代码中的#btnSubmit替换为“.btn hover common”。如果需要更多帮助,请告诉我如何将此样式类用于页面中的所有按钮使用类而不是id并使用每个函数将事件绑定到DOM元素并不需要每个函数可以将类简单地添加到所有按钮btn
,只需将css代码与:hover
告诉我更多帮助您可以告诉我如何将此样式类用于页面中的所有按钮使用类not id并使用每个函数将事件绑定到DOM元素并不需要每个函数简单地将类添加到所有按钮btn
,只需将css代码与:hover
$('#btnSubmit').bind('mouseover', function (event) {
$(this).addClass('ButtonStyle');
})
.bind('mouseleave',function(){
$(this).removeClass('ButtonStyle');
});