你如何逃避reactjs的报价

问题描述 投票:0回答:2

我在我的反应应用程序上转义引号时遇到问题。

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

但那对我不起作用。

javascript reactjs
2个回答
0
投票

请尝试使用单引号。

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

0
投票

如果你想传入值,你也可以使用模板文字

<textarea
  id="values"
  placeholder={`"name": "John", "test": ${value}`}
  onChange={this.handleChange2.bind(this)}
/>
© www.soinside.com 2019 - 2024. All rights reserved.