-2

に問題がありslideUpます。1 つの要素 (最初の要素) だけが上にスライドしています。手を貸してください。ありがとう。以下はコードです:

$(document).ready(function() {
    $('#load').hide();
});
$(function() {
    $("#del").click(function() {
        $('#load').fadeIn();
        $(this).parent().slideUp('slow', function() {$(this).remove();});
        $('#load').fadeOut();
    });
});

そして、ここにマークアップがあります:

<div id="container">
    <table>
        <div id="load" align="center"><img src="images/loading.gif" width="28" height="28"     align="absmiddle"/> loading...</div>
        <tr><td>    
            <span>Ashley Ford</span><br/></td>  
            <td><a href="#" id="del">x</a>  
        </td></tr>
        <tr><td>
            <span>Ashley Ford</span><br/></td>
            <td><a href="#" id="del">x</a>
        </td></tr>
        <tr><td>
            <span>Ashley Ford</span><br/></td>
            <td><a href="#" id="del">x</a>
        </td></tr>  
    </table>
</div>       
4

3 に答える 3

2

From the jQuery docs for the ID selector (emphasis added):

If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM.

You can change your #del elements to use a class name (or some other common characteristic) instead:

<a href="#" class="del">x</a>

And modify your selector accordingly:

$(".del").click(function() {
    //Do stuff
});

As a side note, you have two functions that will be executed on DOM ready. You can combine them into one. Just move the $('#load').hide(); into the other DOM ready event handler.

And it's invalid HTML to have a div as a child of a table element.

于 2012-06-28T11:10:44.227 に答える
1

id複数の要素に同じものを使用することはできません..そのためには、1を使用する必要がありますclass .2に変更してください. この関数id="del"を試してください.class="del"

 $(function() {
      $(".del").click(function() {
      $('#load').fadeIn();
      $(this).parent().slideUp('slow', function() {$(this).remove();});
    $('#load').fadeOut();

    });
     });
于 2012-06-28T11:11:31.307 に答える
0

他の人が述べたように、各要素idは一意でなければなりません。一連の要素をグループ化する必要がある場合、それが要素のclass目的です。

于 2012-06-28T11:11:27.643 に答える