簡體   English   中英

我有一個鼠標懸停功能,可以根據每一行的值從數據庫獲取數據。 但是,它為所有行返回相同的值

[英]I have a mouseover function to get data from the database based on the value of each row. However, it is returning the same values for all row

我需要幫助。 我是第一次嘗試J QUERY。 我有一個鼠標懸停功能,可以根據行ID從數據庫獲取和顯示數據。 但是,所有行的值都相同。 謝謝!

 while($stmt->fetch()){?>

                <td class="other">
                    <input type="hidden"  class="rowid"  value="<?php echo $id ?>"/>
                    <?php echo round($other,2); ?>
                   </td>

        <?php             
        }
        ?>
        //jquery code:
        $(document).ready(function(){
            $(".other ").mouseover(function(){
                var rowid = $('#rowid').val();
                $.get('other.php',{postrowid:rowid},
                    function(data)
                        {
                      $('#otherResult').html(data);
            $('#otherResult').show();
            $(".other").mouseout(function(){
            $('#otherResult').hide();
        });
                    });
                }); 
// Change:
var rowid = $('#rowid').val();

// To:
var rowid = $('input', this).val();

旁注:您可以使用HTML5 data-*屬性將數據添加到相關標簽中, 而不使用隱藏字段:

<td class="other" data-id="<?php echo $id ?>">
    <?php echo round($other,2); ?>
</td>

暫無
暫無

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

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