使用Ionic和React,我想给用户一个选项,当用户从位置字段中选择'Other‘时,输入添加位置字段。
<IonItem lines="none">
<IonLabel position="stacked">Location</IonLabel>
<IonSelect>
<IonSelectOption value="dhaka">Dhaka</IonSelectOption>
<IonSelectOption value="cumilla">
Cumilla
</IonSelectOption>
<IonSelectOption value="barisal">
Barisal
</IonSelectOption>
<IonSelectOption value="sylet">Sylet</IonSelectOption>
<IonSelectOption value="other">Other</IonSelectOption>
</IonSelect>
</IonItem>
<IonItem lines="none">
<IonLabel position="stacked">Add Location</IonLabel>
<IonInput type="text" className="custom-input"></IonInput>
</IonItem>发布于 2020-12-06 07:51:27
我给你一个主意:
const Options = ()=>{
const [select,setSelect]= React.useState();
//handler function
const handleCapacity=(e)=>{
setSelect(e.target.value);
}
return (
<React.Fragment>
<select value={select} onChange={handleCapacity}>
<option>1</option>
<option>2</option>
<option>other</option>
</select>
{select==="other"&& <input type="text"/>}
</React.Fragment>
)
}
ReactDOM.render(
<Options />,
document.getElementById("react")
);<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="react"></div>
https://stackoverflow.com/questions/65165536
复制相似问题