Escaping double quotes in JavaScript

后端 未结 2 1430
情书的邮戳
情书的邮戳 2020-12-20 08:50

I have this code:

 facetsString += "  " + facetList[count].te         


        
相关标签:
2条回答
  • 2020-12-20 09:25

    You can escape double quotes like this:

    "string with \"double qoutes\""
    

    The solution is:

    facetsString += "<td><input type='checkbox' value=\"" + facetList[count].term + "\">&nbsp;&nbsp;" + facetList[count].term + " (" + facetList[count].count + ")" + "</td>";
    

    The example provided would write facetList[count].term in the value attribute, and not the actual value of the variable.

    0 讨论(0)
  • 2020-12-20 09:32

    Just put a backslash in front of the double-quotes:

    facetsString += "<td><input type='checkbox' value=\"facetList[count] ... \" /></td>"
    

    Alternatively, you can wrap the outer in single quotes, and use double quotes for property values:

    facetsString += '<td><input type="checkbox" value="facetList[count] ... " /></td>'
    
    0 讨论(0)
提交回复
热议问题