本文介绍了在JavaScript中转义双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码:
facetsString += "<td><input type='checkbox' value=facetList[count].term> " + facetList[count].term + " (" + facetList[count].count + ")" + "</td>";
我正在尝试为每个复选框赋予唯一值facetList[count].term
,但是我不知道如何转义双引号...
I'm trying to give each checkbox a unique value facetList[count].term
, but I don't know how to escape the double quotes...
推荐答案
您可以这样对双引号进行转义:
You can escape double quotes like this:
"string with \"double qoutes\""
解决方案是:
facetsString += "<td><input type='checkbox' value=\"" + facetList[count].term + "\"> " + facetList[count].term + " (" + facetList[count].count + ")" + "</td>";
提供的示例将在值属性中写入facetList[count].term
,而不是变量的实际值.
The example provided would write facetList[count].term
in the value attribute, and not the actual value of the variable.
这篇关于在JavaScript中转义双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!