Jquery 更改css背景属性在IE中不起作用
我有一个html表格:Jquery 更改css背景属性在IE中不起作用,jquery,css,Jquery,Css,我有一个html表格: <table id=mytable> <tr> <th>Configurations</th> <th>Dual 1.8GHz</th> <th>Dual 2GHz</th> <th>Dual 2.5GHz</th> </tr> </table> 配置 双1.8GHz 双2GHz 双2.5GHz 然后我写了以下内容: &l
<table id=mytable>
<tr>
<th>Configurations</th>
<th>Dual 1.8GHz</th>
<th>Dual 2GHz</th>
<th>Dual 2.5GHz</th>
</tr>
</table>
配置
双1.8GHz
双2GHz
双2.5GHz
然后我写了以下内容:
<script type="text/javascript">
$('#mytable tr').hover(
function () {
$(this).css("background","yellow");
},
function () {
$(this).css("background","");
}
);
</script>
$('#mytable tr')。悬停(
函数(){
$(this.css(“背景”、“黄色”);
},
函数(){
$(this.css(“背景”和“”);
}
);
当我将鼠标悬停在表格行上时,它在Firefox中变为黄色,但在IE中变为白色!有什么想法吗?替换
$(this).css("backgroundColor","yellow");
及
或者可以传递css属性对象
$(this).css({
background-color: 'yellow',
background-image: 'url("blablabla")'
});
做:
.someClass{/*所有要设置的程序*/}
$('#mytable tr')。悬停(
函数(){
$(this.addClass('someClass');
},
函数(){
$(this.removeClass('someClass'))
}
);
对于IE,请尝试backgroundColor而不是Background。我在IE9上测试了您的代码,它是黄色的。注意:使用CSS会更干净、更可靠<代码>表格tr:hover{背景色:黄色;}
$(this).css({
background-color: 'yellow',
background-image: 'url("blablabla")'
});
$(this).css("backgroundColor","yellow");
//or
$(this).css("background-color","yellow");
<style>
.someClass{/*all the proertiese you wanna set*/}
</style>
$('#mytable tr').hover(
function () {
$(this).addClass('someClass');
},
function () {
$(this).removeClass('someClass')
}
);