文本框“this.value”用单引号停止 JavaScript
我无法在 JavaScript this.value
中使用单引号。双引号工作正常。我尝试使用 escape()
但它不起作用,而且我想不出使用 PHP 来解决此问题的方法,那么其他人有什么想法吗?
function editItemInCart(newValue,fieldName,itemNum,cnt) {
//alert(newValue);
if (count == cnt) {
count = 0;
jQuery.ajax({
type:"POST",
url: "editItem.html",
data: "newvalue=" + escape(newValue) + "&fieldname=" + fieldName + "&itemNum=" + itemNum,
})
document.getElementById('status' + itemNum).innerHTML = "SAVED";
jQuery("#status" + itemNum).show();
setTimeout("fade_out('"+itemNum+"')", 1000);
}
//alert(newValue + fieldName + itemNum);
}
if ($cart['title'] != "")
echo "<label>Title: </label> <input type=\"text\" onKeyUp=\"doEditItemInCart(this.value,'title',".$itemNum.")\" onChange=\"editItemInCart(this.value,'title',".$itemNum.")\" value=\"".htmlspecialchars($cart['title'])."\"><br />";
function doEditItemInCart(newValue,fieldName,itemNum) {
count++;
setTimeout("editItemInCart(escape('"+newValue+"'),'"+fieldName+"',"+itemNum+","+count+")",200);
}
I cannot get single quotes to work in JavaScript this.value
. Double quotes work fine. I tried to use escape()
and it didn't work and I cannot think of a way to use PHP to fix this, so does anyone else have any ideas?
function editItemInCart(newValue,fieldName,itemNum,cnt) {
//alert(newValue);
if (count == cnt) {
count = 0;
jQuery.ajax({
type:"POST",
url: "editItem.html",
data: "newvalue=" + escape(newValue) + "&fieldname=" + fieldName + "&itemNum=" + itemNum,
})
document.getElementById('status' + itemNum).innerHTML = "SAVED";
jQuery("#status" + itemNum).show();
setTimeout("fade_out('"+itemNum+"')", 1000);
}
//alert(newValue + fieldName + itemNum);
}
if ($cart['title'] != "")
echo "<label>Title: </label> <input type=\"text\" onKeyUp=\"doEditItemInCart(this.value,'title',".$itemNum.")\" onChange=\"editItemInCart(this.value,'title',".$itemNum.")\" value=\"".htmlspecialchars($cart['title'])."\"><br />";
function doEditItemInCart(newValue,fieldName,itemNum) {
count++;
setTimeout("editItemInCart(escape('"+newValue+"'),'"+fieldName+"',"+itemNum+","+count+")",200);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下
,您似乎正在设置已保存的状态,无论 ajax 响应如何。我建议添加一个ajax成功功能
http://api.jquery.com/jQuery.ajax/
try this
it also appears that you are setting the status of saved regardless of the ajax response. i suggest added an ajax success function
http://api.jquery.com/jQuery.ajax/