簡體   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