【问题标题】:Is there a way in react native to have a permanent placeholder inside of a text input?有没有办法在本机反应中在文本输入中使用永久占位符?
【发布时间】:2019-01-07 15:34:12
【问题描述】:

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    一种解决方案是在输入值中显示额外的“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

    【讨论】:

    • 谢谢!这正是我想要做的!非常感谢!!
    猜你喜欢
    • 2019-09-28
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    相关资源
    最近更新 更多