我需要帮助。我是第一次尝试 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>
关于php - 我有一个鼠标悬停功能,可以根据每行的值从数据库获取数据。但是,它为所有行返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36946349/