2

我的问题可能有点不清楚,所以我举个例子

    <table id="products">
        <tr id="P1" class="A1"><td>1x</td><td>Product 1</td><td>&euro; 9,50</td><td><a href="#">(x)</a></td></tr>
        <tr id="P2" class="A1"><td>1x</td><td>Product 2</td><td>&euro; 10,50</td><td><a href="#">(x)</a></td></tr>
    </table>

我想要完成的是以下功能

    $('#bestelling tr').each(function(index) {
        var naam = $(this + " td + td").text();
        var id = $(this).attr('id'); 
        alert(id + " " + naam);
    });

有谁知道我怎么能做到这一点?对不起,我对这个问题的简短解释我的英语不是那么好。

4

2 回答 2

1
$('#bestelling tr td:eq(1)').each(function(index) {
    var naam = $(this).text();
    var id = this.id; 
    alert(id + " " + naam);

    // The tr is:
    $(this).parent()
    // Or the DOM element:
    this.parentNode 
});
于 2012-06-25T23:14:32.893 回答
0
here you go mate. Run the code below: 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>How to get element after current selector</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('table tr').click(function (e) {
                var naam = "";
                $(this).children().each(function () {
                    naam += $(this).html() + ' ';
                });

                alert(naam);
            });

        });
    </script>

</head>
<body>
<table id="products">
    <tr id="P1" class="A1">
        <td>1x</td>
        <td>Product 1</td>
        <td>&euro; 9,50</td>
        <td><a href="#">(x)</a></td>
    </tr>
    <tr id="P2" class="A1">
        <td>1x</td>
        <td>Product 2</td>
        <td>&euro; 10,50</td>
        <td><a href="#">(x)</a></td>
    </tr>
</table>

</body>
</html>
于 2012-06-25T23:23:27.147 回答