在鼠标悬停事件 jquery 上显示边框的内容

What to show border on mouseover event jquery

本文关键字:边框 显示 鼠标 悬停 事件 jquery      更新时间:2023-09-26
    $(document).ready(function () {
        $("[data-role=content]").not("#ft").children().live({ 
        mouseover: function () { $(this).css({ border: "1px solid gray" }); }, 
        mouseleave: function () { $(this).css({ border: "0" }); } });
    });

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

来自.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]元素未嵌套的情况下才能正常工作。

演示