【发布时间】:2018-08-26 07:23:11
【问题描述】:
我想要带有单选按钮的下拉菜单,当我单击字段时需要显示该按钮,当我单击外部并在输入字段中获取所选值时隐藏。我有部分工作代码。
- 下拉菜单打开后,我无法隐藏它。
- 我需要输入字段中的选定值,而不是我拥有的占位符值。
我看到很多选择选项下拉列表的答案,但标签占位符没有。
//Not sure why the above function is not hiding the dropdown
RadioDdOnclick() {
var x=document.getElementById("radiobtn");
if (x.style.display==="none") {
document.getElementById('RadioDd').style.visibility='hidden'; //i tried style.display ='none';
}
else {
document.getElementById('RadioDd').style.display='block';
}
}
<div className="inputWithIcon" onClick={this.RadioDdOnclick} id="radiobtn">
<input className="inputBlock" id="radioSelect" type="text" placeholder="choose one" />
<i className="fa fa-angle-down" />
</div>
<div className={ "BudgetRadioDd"} id={ "RadioDd"} style={{display: 'none'}}>
<fieldset>
<h4>options to choose</h4>
<div>
<label><input type="radio" id="1"/>option 1</label>
</div>
<div>
<label> <input type="radio" id="2" />option 2</label>
</div>
<div>
<label><input type="radio" id="3"/>option 3</label>
</div>
</fieldset>
</div>
//css code here
.input[type=text]{
width:100%;
border:2px solid #aaa;
border-radius:4px;
margin:8px 0;
outline:none;
padding:8px;
box-sizing:border-box;
transition:.3s;
}
.inputWithIcon{
position:relative;
}
.inputWithIcon i{
position:absolute;
right: 3%;
top: 0;
font-size: 25px;
padding: 20px 8px;
color:#c69937;
transition:.3s;
}
更新 下面的答案是有效的,但它正在另一个 div 组件中呈现无线电值。
寻找更好的解决方案..
添加查看问题的链接:https://stackblitz.com/edit/react-feubq6?file=index.js
【问题讨论】:
-
将此 className={"BudgetRadioDd"} id={"RadioDd"} 更改为 className="BudgetRadioDd" id="RadioDd"
-
您能否将CSS代码以及不带括号的HTML中的工作类分享给我们,以便我们为您提供帮助?
-
用你的HTML DOM很难实现。你需要先安排DOM
-
@think-twice 我不认为花括号在这里是 prblm。
-
@MuhammadOsama 我只有箭头位置的 CSS。
标签: javascript html reactjs