在React主页示例中,他们使用(不懂 HTML 语法)和 library .,如果您只想使用 HTML从方法中删除-markdownmarkdownRemarkableRemarkablerawMarkup{ __html: this.state.value }
var HTMLEditor = React.createClass({
getInitialState: function() {
return {value: 'Put here <h1>HTML</h1>'};
},
handleChange: function(e) {
this.setState({ value: e.currentTarget.value });
},
markup: function() {
return { __html: this.state.value };
},
render: function() {
return (
<div className="html-editor">
<textarea
onChange={ this.handleChange }
defaultValue={this.state.value} />
<div
className="html-editor__content"
dangerouslySetInnerHTML={ this.markup() }
/>
</div>
);
}
});
ReactDOM.render(<HTMLEditor />, document.getElementById('container'));Run Code Online (Sandbox Code Playgroud)
.html-editor {
border: 1px solid #000;
padding: 10px;
}
.html-editor__content {
margin: 10px 0 0 0;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="container"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11016 次 |
| 最近记录: |