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");
        });
});

私のページには、同じ名前 ("divHeader") の 3 つの div がありますが、最初の div のみを適用し、他の 2 つをスキップします。

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 に答える