无法在jquery javascript中转义字符

时间:2016-05-20 13:54:42

标签: javascript jquery

我需要逃避"在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"'

1 个答案:

答案 0 :(得分:3)

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

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