我正在开发一个PHP代码,当页面运行时,它将显示带有Update按钮选项的动态记录。现在的问题是它是动态生成的,所以当单击一个按钮时,如何获取表记录的特定COLUMN值?
答案 0 :(得分:0)
PHP创建表
echo "<table>";
echo "<tr>";
while( ($row = mysql_fetch_array($result)))
{
echo "<td>".$row['no']."</td>";
echo "<td>".$row['notify']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['url']."</td>";
echo "<td><input type='button' name='update' onClick='updateRecord(this)' id='update' value='".$row['id']."'></td>";
}
echo "</tr>";
echo "</table>";
JavaScript更新记录
function updateRecord(id)
{
var recordId = id.value;
...Update record through ajax call...
...Update record through form submit...
}
通过ajax调用更新记录
$.ajax({
url: 'update.php',
method: 'GET',
data: 'userID=' + recordId,
success: function(new_data){
$(popID).html(new_data);
$(popID).dialog();
alert('Load was performed.');
}
});