簡體   English   中英

這個數字沒有增加

[英]the number doesn't increase

我有這樣一個問題, 這個 單擊后第一行號增加,但是單擊后第二行號不增加。 我希望點擊后所有數字都增加。 我認為jquery代碼是錯誤的,請有人幫我修復我的jquery代碼。

我的代碼:

<?php
    include("mwcon.php");
?>
<html>
<head>
    <link rel='stylesheet' type='text/css' href='/css/post.css'>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#post-vote-top").click(function () {
                $("#post-vote-middle").text(function(){
                    return ~~$(this).text() + 1
                });
            });             
        });
    </script>
</head>
<body>
<?php
    echo "
        <div id='post'>
            <table>
    ";
    $no=1;
    $q=mysql_query("SELECT * FROM t_post");
    while($f=mysql_fetch_object($q)){
        echo "
            <tr>
                <td id='post-nomor'>$no.</td>
                <td id='post-vote' align='center'>
                    <div id='main'>
                        <div id='post-vote-top'></div>
                        <div id='post-vote-middle'>$f->vote</div>
                        <div id='post-vote-bottom'></div>
                    </div>
                </td>
                <td><a href='$url' target='_blank'><img src='$f->linkimg' width='80' height='50'></img></a></td>
            </tr>
        ";
        $no++;
    }
    echo "
            </table>
        </div>
    ";
?>
</body>
</html>

請幫我。 謝謝。

id應該是唯一的使用class 您可以在單擊元素之后立即使用next()選擇元素

 $(document).ready(function() { $(".post-vote-top").click(function() { $(this).next(".post-vote-middle").text(function(i, v) { return parseInt(v, 10)+1; }); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tr> <td id='post-nomor'>$no.</td> <td id='post-vote' align='center'> <div class='main'> <div class='post-vote-top'>up</div> <div class='post-vote-middle'>1</div> <div class='post-vote-bottom'></div> </div> </td> <td></td> </tr> <tr> <td id='post-nomor'>$no.</td> <td id='post-vote' align='center'> <div class='main'> <div class='post-vote-top'>up</div> <div class='post-vote-middle'>1</div> <div class='post-vote-bottom'></div> </div> </td> <td></td> </tr> </table> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM