简体   繁体   English

这个数字没有增加

[英]the number doesn't increase

I have a problem like this . 我有这样一个问题, 这个 The first row number is increase after clicked, but the second row number doesn't increase after clicked. 单击后第一行号增加,但是单击后第二行号不增加。 I want all of the number is increase after clicked. 我希望点击后所有数字都增加。 I think jquery code is wrong, please somebody help me to fix my jquery code. 我认为jquery代码是错误的,请有人帮我修复我的jquery代码。

my code: 我的代码:

<?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>

Please help me. 请帮我。 Thank you. 谢谢。

id should be unique use class instead. id应该是唯一的使用class You can use next() to select element immediately after clicked element 您可以在单击元素之后立即使用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