将单引号和双引号的值附加到文本框

Vig*_*ian 9 html javascript regex jquery

我需要将结果数据集中的值附加到input可能具有任何特殊字符*^&$#>,'"等的值.问题是我无法将整个数据追加varinput.

请检查这个小提琴.我错过了什么?

我不能做到这一点,而无需使用.find.append喜欢这个

Vig*_*ian 3

.find因此,为了在不单独使用或附加的情况下解决这个问题var,我找到了一个简单的解决方案。我只需要用其 iso 拉丁代码替换single quote'' ” ,将其他特殊字符替换为各自的代码,然后在中使用该变量.html

var something= "this is vicky\"s \"s 's 's \"s \"S";
test=something.replace(/'/g,"'").replace(/"/g,'\\"');
$("#test").html("hey this is <input id='testbox' value='"+test+"'></input>");
Run Code Online (Sandbox Code Playgroud)

看看这个 jsfiddle