如何在JavaScript中转义",<和所有特殊字符

vin*_*mar 2 html javascript escaping

如何在javaScript中转义所有特殊字符.

我们正在使用它,但它不起作用:

<input type = "text" value="' }{ " : ? > < \ ] [ ' ; / . ,">
Run Code Online (Sandbox Code Playgroud)

Nin*_*olz 5

你只需要交换"使用&quot;.

一个好主意是采取更多的HTML实体:

  • < 用...来代替 &lt;
  • > 用...来代替 &gt;

<input type = "text" value="' }{ &quot; : ? &gt; &lt; \ ] [ ' ; / . ,">
Run Code Online (Sandbox Code Playgroud)