因此,我使用php/mysql生成一个表,并在此表中使用行中的数字。我点击了一个按钮,在MySQL数据库中为此数字值添加+1。问题是,我必须刷新页面以显示新表中的新号码。Jquery如何将+1添加到表中的数字
我试图通过jQuery按钮点击事件的成功上的函数立即显示新的数字。所以基本上我需要识别表格中HTML生成的数字,然后为其添加+1。
问题是,该表是用生成的,而函数在php中生成,所以每一行都在运行中获得自己的ID。
希望这一切都有道理。
这是我的JQuery代码到目前为止。
$('.upArrow').click(function(){
//this is finding the uparrow button that adds +1
var row = $(this).attr('rowid');
$.ajax({
type: "GET",
url: "upArrow.php?id="+row,
cache: false,
async: false,
success: function(result){
//this is tricky part, how do I select the displayed number part of the
// table, then Add 1?
},
error: function(result){
alert('Error, please try again.');
}
});
});
编辑:这是我的一块HTML表:
<td id="musicDisplay" colspan="2">
<div id="newUpArrow">
<a href="javascript:void(0)" class = "upArrow"
rowid="' . $row['id'] . '"><img src="../Img/upArrow.gif"/>
</a> </div>
<!--Here is the number I want to change.-->
<div>'. $row['points'] . '</div>
</td>
和'table'的html? – 2011-05-12 18:27:42
我第一次刚读* Jquery如何给一个数字添加+1,并且认为OMG ....;)请张贴您的HTML。您也不应该为此使用GET请求。 Ajax可以,但如果有人只是在地址栏中输入它,并且正在浏览历史记录等,则值可能会不自觉地增加。 – 2011-05-12 18:29:31