繁体   English   中英

你如何转义 reactjs 中的引号

[英]How do you escape quotes in reactjs

我的 React 应用程序中的 escaping 引号有问题。

<textarea id="values" 
          placeholder="{ "name": "John", "test": true}" 
          onChange={this.handleChange2.bind(this)}>
</textarea>

我试过这样做:

<textarea id="values"
          placeholder="{ \"name\": \"John\", \"test\": true}" 
          onChange={this.handleChange2.bind(this)}>
</textarea> 

但这对我不起作用。

尝试改用单引号。

<textarea id="values" 
    placeholder='{ "name": "John", "test": true}'
    onChange={this.handleChange2.bind(this)}>
</textarea>

要么

将引号移到{}内

<textarea id="values" 
    placeholder={"\"name\": \"John\", \"test\": true"}
    onChange={this.handleChange2.bind(this)}>
</textarea>

如果您要传递值,也可以使用模板文字

<textarea
  id="values"
  placeholder={`"name": "John", "test": ${value}`}
  onChange={this.handleChange2.bind(this)}
/>
<p>&quot;What if this? what if that?&quot;</p>

   "What if this? what if that?"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM