首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jQuery on()函数和悬停事件

jQuery on()函数和悬停事件
EN

Stack Overflow用户
提问于 2013-07-20 14:25:44
回答 6查看 133关注 0票数 0

我正在使用ajax将XML加载到一个表中,并尝试执行"hover“事件,以便在将鼠标悬停在表行内和表外时更改颜色。表行是使用AJAX动态添加的。这不管用。代码如下:

代码语言:javascript
复制
$(document).ready(function(){
    //$("tr").hover(function(){
    $("#tbl1").on("hover","tr",function(){
       $(this).attr('bgcolor', "yellow");
    },
    function(){
       $(this).attr('bgcolor', "white");
    });     
});

下面是页面加载时的表格

代码语言:javascript
复制
<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>

提前感谢您的帮助

EN

Stack Overflow用户

发布于 2013-07-20 14:35:12

使用.css()而不是.attr()

代码语言:javascript
复制
$(document).ready(function () {
    $("#tbl1 tr").hover(function () {
        $(this).css("background-color", "yellow");
    },

    function () {
        $(this).css("background-color", "white");
    });
});

检查此

票数 0
EN
查看全部 6 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17759388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档