使用jQuery更改背景颜色 [英] Change background color using jQuery
本文介绍了使用jQuery更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jQuery更改背景颜色.我究竟做错了什么?我知道使用CSS可以轻松得多,但是我正在尝试使用jQuery.
I am trying to change the background color with jQuery. What am I doing wrong? I know this can be done with CSS a lot easier but I am trying to do it with jQuery.
链接到 jsfiddle .我正在尝试将嗨"的背景更改为黄色.
Link to jsfiddle. I am trying to change the background of "Hi" to yellow.
window.onload=function(){
$('.myClass td').css({'background-color': 'yellow'});
}
<table>
<tr class="myClass">
<td>Hi</td>
</tr>
<tr>
<td>Bye</td>
</tr>
</table>
推荐答案
为您的JS使用document.ready.
Use document.ready for your JS.
$(document).ready(function(){
$('.myClass td').css({'background-color': 'yellow'});
});
这篇关于使用jQuery更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文