我在我的反应应用程序上转义引号时遇到问题。
<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)}
/>