文本框“this.value”用单引号停止 JavaScript

发布于 2024-12-01 13:13:10 字数 1145 浏览 1 评论 0原文

我无法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-12-08 13:13:11

尝试一下

        jQuery.ajax({type:"POST",
            url: "editItem.html?newvalue=" + escape(newValue) + "&fieldname=" + fieldName + "&itemNum=" +   itemNum,
         })

,您似乎正在设置已保存的状态,无论 ajax 响应如何。我建议添加一个ajax成功功能
http://api.jquery.com/jQuery.ajax/

try this

        jQuery.ajax({type:"POST",
            url: "editItem.html?newvalue=" + escape(newValue) + "&fieldname=" + fieldName + "&itemNum=" +   itemNum,
         })

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文