reactjs - 当使用离子反应从选择框中选择其他选项时显示输入字段
问题描述
使用 Ionic 和 React,当用户从位置字段选择框中选择选项“其他”时,我想为用户提供一个选项以输入添加位置字段。
<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>
解决方案
生病给你的想法:
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>
推荐阅读
- excel - 回复:VBA-(VLOOKUP)+(值+1)
- sql - 将 db 值与文本框值 VB 进行比较
- javascript - Javascript/typescript 循环一次处理来自数组的一个命令
- c# - 检查程序是否有权移动文件
- mongodb - 将嵌套数组与 mongo 进行比较
- c# - C# 数学回合在 0.8 上而不是在 0.5 上
- javascript - 在 Xpage 上运行“Repeatagent”
- node.js - 使用 PUT 请求生成签名 url 以将对象上传到 Google Cloud Storage 时,禁止获取 403
- selenium - 用于启动应用的 Activity 不存在或无法启动 Appium
- oracle - PL/SQL 选择列值到变量中