【问题标题】:Can't escape character in jquery javascript [duplicate]无法在jquery javascript中转义字符[重复]
【发布时间】:2016-09-17 19:52:52
【问题描述】:

我需要在 jquery 字符串中转义 ",但是 " 不打印。我正在使用 \" 来逃避它。

$form.append(name +' <input type="checkbox" class="team" id="team" 
data-value1="age:'+ age +'" data-value2="fav_color = '  + color +' "/>


$form.append(name +' <input type="checkbox" class="team" id="team" 
data-value1="age: \"'+ age +' \"" data-value2="fav_color = \"'  + color +' "\"/>

 result = 'age: 12' for both

我需要

 result = 'age: "12"'

【问题讨论】:

标签: javascript jquery


【解决方案1】:

您需要使用html实体,例如:

$form.append(name +' <input type="checkbox" class="team" id="team" data-value1="age:&quot;'+ age +'&quot;" data-value2="fav_color = '  + color +' "/>');

【讨论】:

    猜你喜欢
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    相关资源
    最近更新 更多