答案 0 :(得分:0)
一种解决方案是在输入值中显示附加的“ To”,然后对结果字符串进行切片以避免将占位符放入结果中。
一个工作示例:
class MyInput extends React.Component {
constructor(props) {
super(props)
this.state = {
text: ''
}
}
textChanged = event => {
this.setState({ text: event.target.value.slice(5) })
}
render = () => <input type='text' value={'To : ' + this.state.text} onChange={this.textChanged}/>
}
ReactDOM.render(<MyInput />, document.getElementById('root'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.1/umd/react-dom.production.min.js"></script>
<div id='root'>
这是Web React应用程序的答案,您可以将输入更改为TextBox