0
    $(document).ready(function () {
        $("[data-role=content]").not("#ft").children().live({ 
        mouseover: function () { $(this).css({ border: "1px solid gray" }); }, 
        mouseleave: function () { $(this).css({ border: "0" }); } });
    });

这是行不通的。没有显示边框。谁能告诉我我错在哪里?

4

1 回答 1

1

.live文档中:

不支持链接方法。例如,$("a").find(".offsite, .external").live( ... );无效且无法按预期工作。

因此$(...)....children().live()不会工作。

改用.on

$("[data-role=content]").not("#ft").on( {
    mouseover: function () { 
        $(this).css({ border: "1px solid gray" }); 
    }, 
    mouseleave: function () { 
        $(this).css({ border: "0" }); 
    }
}, '[data-role=content] > *');

不幸的是,似乎不可能仅用> *作事件委托的选择器。当然[data-role=content] > *只有在 [data-role=content]元素没有嵌套的情况下才能正常工作。

演示

于 2012-05-30T10:24:20.330 回答