我正在使用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:36:27
试试这个:
$(document).ready(function() {
$("#tbl1").on("mouseenter", "tr", function() {
$(this).attr('bgcolor', "yellow");
}).on("mouseleave", "tr", function() {
$(this).attr('bgcolor', "white");
});
});发布于 2013-07-20 14:30:05
使用此函数
$("#tbl1 tr").live("hover",function(){
$(this).attr('bgcolor', "yellow");
},
function(){
$(this).attr('bgcolor', "white");
}); 发布于 2013-07-20 14:31:06
尝尝这个
$(document).ready(function(){
$("#tbl1").on("mouseenter","tr",function(){
$(this).attr('bgcolor', "yellow");
},
function(){
$(this).attr('bgcolor', "white");
});
});hover是鼠标输入和鼠标离开事件的简写形式。悬停本身并不是一个事件。和.on('hover'..不是有效语法。但是,您可以直接使用$(“#tbl1tr”)函数(.hover() {})。
https://stackoverflow.com/questions/17759388
复制相似问题