gpt4 book ai didi

javascript - 未捕获的语法错误 : Unexpected token } with unknow reason

转载 作者:行者123 更新时间:2023-11-27 22:30:47 25 4
gpt4 key购买 nike

我得到了一个意外 token },但我不知道为什么。

enter image description here

这是一张 table ,上面有一些按钮。单击按钮时,它将调用 Javascript 函数。

这是我的代码:

<tbody>
<?php $i = 0; foreach ($query as $row){?>
<tr>
<td><?php echo ++$i; ?></td>
<td><?php echo $row['address'] . ", " . $row['city'] . ", " . $row['state'] . ", " . $row['country']; ?></td>
<td>
<button id ="delete" class = "delete" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?> onClick="deleteAddress(this.value)">delete</button>
</td>
<td>
//Print this <button id = "edit" class = "edit" type="button" value="7" onClick = "editAddress( this.value, "23", "323", "323", "iij")" >Edit</button>
<button id = "edit" class = "edit" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?> onClick = <?php echo "\"editAddress( this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")\""; ?> >Edit</button></td>
</tr>
</tbody>

 function editAddress(id, address, city, state, country)
{
document.getElementById("address_field").value = address;
document.getElementById("city_field").value = city;
document.getElementById("state_field").value = state;
document.getElementById("country_field").value = country;
document.getElementById("add_new").innerHTML = 'Update Address';
document.getElementById("add_new").value = id;
document.getElementById("add_new").onclick = function() {
var id = document.getElementById("add_new").value;
var address = document.getElementById("address_field").value;
var city = document.getElementById("city_field").value;
var state = document.getElementById("state_field").value;
var country = document.getElementById("country_field").value;

jQuery.ajax({
type: "POST",
url: "../wp-content/plugins/add_address_list/insert_address.php",
data: {functionName : "updateAddress", id : id, address : address, city : city, state : state, country : country},
success: function(msg){
window.location.reload();
}
});
};
}

IDE 没有任何语法错误。不知道为什么。谢谢。

最佳答案

错误在于:

onClick = "editAddress( this.value, "23", "323", "323", "iij")"

或者更确切地说:

onClick = <?php echo "\"editAddress( this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")'"; ?> >Edit</button>

应该是:

<button id = "edit" class = "edit" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?>  onClick ='<?php echo "editAddress( this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")"; ?> >Edit</button></td>

只需用 ' 括住 JavaScript,因此允许使用双引号,因此它看起来像:

onClick = 'editAddress( this.value, "23", "323", "323", "iij")'

关于javascript - 未捕获的语法错误 : Unexpected token } with unknow reason,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com