好吧,我有一个表生成器,带有mysql db的数据。
首先,代码:
PHP
while($result = mysqli_fetch_assoc($SQL)){
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Name')' contentEditable = 'true'>" . $result['Name'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Username')' contentEditable = 'true'>" . $result['Username'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Email')' contentEditable = 'true'>" . $result['Email'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Grade')' contentEditable = 'true'>" . $result['Grade'] . "</p>" );
$tbl->addCell("<input type = 'button' class = 'Edit-TBB' value = 'Edit'>
<input type = 'button' class = 'Delete-TBB' value = 'Delete'>");
$tbl->addRow();
}
AJAX
function editTable(id, new_text, column) {
$.ajax({
url: "../PHP/Configuracion/edit_grade.php",
type: "POST",
data: 'id='+id+'&text='+new_text.innerText,
success: function(data){
alert(column);
}
});
}
以下是问题:
我有'editTable(" . $result['id_user'] . ", this, 'Name')'
如果我更改Chrome中的代码,例如this ...这样可行,但我不知道我需要在代码编辑器中更改内容。
我需要改变什么?
谢谢!
答案 0 :(得分:0)
您必须对onBlur
值使用双引号,因为您使用单引号将js字符串表示为参数。要做到这一点,你需要在你的PHP中转义双引号。因此,将addCell
调用更改为:
addCell("<p onBlur=\"editTable(" . $result['id_user'] . ", this, 'Name')\" contentEditable = 'true'>");