2
$(document).ready(function () {   
    $("#divHeader")) {
        $(this).hover(function () {
            $(this).find('#edit').show();
            $(this).find('#spandate').removeClass("datetime");
            $(this).find('#spandate').addClass("edit");
        },
        function () {
            $(this).find('#edit').hide();
            $(this).find('#spandate').addClass("datetime");
            $(this).find('#spandate').removeClass("edit");
        });
});

在我的页面中,我有 3 个具有相同名称的 div ("divHeader") ,但它仅适用于第一个 div 并跳过其他两个。

请告诉我如何申请所有使用ID?

4

1 回答 1

0
$(".aClass").hover(function () {
         $(this).find('#edit').show();
         $(this).find('#spandate').removeClass("datetime");
         $(this).find('#spandate').addClass("edit");
     },
     function () {
         $(this).find('#edit').hide();
         $(this).find('#spandate').addClass("datetime");
         $(this).find('#spandate').removeClass("edit");
});

创建一个类,示例显示“aClass”,并使用它。如图所示,in out 的事件处理程序将在悬停的 div 中找到 id 为 spandate 的元素。

于 2012-06-29T13:02:15.537 回答