React native “如何清除文本输入”;占位符;当用户点击输入时?
我想知道当用户点击字段填充时,如何清除文本输入中的“占位符” 这是我的文本输入:React native “如何清除文本输入”;占位符;当用户点击输入时?,react-native,textinput,React Native,Textinput,我想知道当用户点击字段填充时,如何清除文本输入中的“占位符” 这是我的文本输入: <TextInput style={{height:40, borderColor: 'gray', borderWidth:1}} onChangeText={(text) => this.setStoreName(text)} value={this.state.storeName} /> 提前感谢。使用带有值的占位符 您应该像这样使用TextInput: const
<TextInput
style={{height:40, borderColor: 'gray', borderWidth:1}}
onChangeText={(text) => this.setStoreName(text)}
value={this.state.storeName}
/>
提前感谢。使用带有值的
占位符
您应该像这样使用TextInput
:
constructor(props) {
super(props)
this.state = {
name: "",
storeName: "",
email: "",
address: "",
city: "",
category: "",
password: "",
placeholder: "initial value"
}
}
<TextInput
style={{height:40, borderColor: 'gray', borderWidth:1}}
onChangeText={(text) => this.setStoreName(text)}
value={this.state.storeName}
placeholder={this.state.placeholder}
onFocus={() => this.setState(placeholder: '')}
/>
构造函数(道具){
超级(道具)
this.state={
姓名:“,
店名:“,
电邮:“,
地址:“,
城市:“,
类别:“,
密码:“”,
占位符:“初始值”
}
}
this.setStoreName(text)}
值={this.state.storeName}
占位符={this.state.placeholder}
onFocus={()=>this.setState(占位符:“”)}
/>
当然,最好在类体中的render
函数之外定义函数,并在JSX中使用它们 一旦设置为空字符串“”,除非重新加载,否则将不会再次设置“初始值”
<TextInput
style={{height:40, borderColor: 'gray', borderWidth:1}}
onChangeText={(text) => this.setStoreName(text)}
value={this.state.storeName}
placeholder="Le nom de votre commerce"
/>
constructor(props) {
super(props)
this.state = {
name: "",
storeName: "",
email: "",
address: "",
city: "",
category: "",
password: ""
}
}
constructor(props) {
super(props)
this.state = {
name: "",
storeName: "",
email: "",
address: "",
city: "",
category: "",
password: "",
placeholder: "initial value"
}
}
<TextInput
style={{height:40, borderColor: 'gray', borderWidth:1}}
onChangeText={(text) => this.setStoreName(text)}
value={this.state.storeName}
placeholder={this.state.placeholder}
onFocus={() => this.setState(placeholder: '')}
/>