我正在使用ajax将XML加载到一个表中,并尝试执行"hover“事件,以便在将鼠标悬停在表行内和表外时更改颜色。表行是使用AJAX动态添加的。这不管用。代码如下:
$(document).ready(function(){
//$("tr").hover(function(){
$("#tbl1").on("hover","tr",function(){
$(this).attr('bgcolor', "yellow");
},
function(){
$(this).attr('bgcolor', "white");
});
});下面是页面加载时的表格
<table width="200" border="5" cellspacing="5" cellpadding="5" id="tbl1">
<tr>
<th scope="col">Index</th>
<th scope="col">Matriks</th>
<th scope="col">Name</th>
<th scope="col">IC</th>
<th scope="col">Age</th>
<th scope="col">Photo</th>
</tr>
</table>提前感谢您的帮助
发布于 2013-07-20 14:35:12
使用.css()而不是.attr()
$(document).ready(function () {
$("#tbl1 tr").hover(function () {
$(this).css("background-color", "yellow");
},
function () {
$(this).css("background-color", "white");
});
});检查此
https://stackoverflow.com/questions/17759388
复制相似问题