Javascript 如何选择<;李>;在reactjs的按钮范围中,下拉列表
没用。如何处理此代码?也许使用TabCydiy='1,2,3/P>>P>使用OnFooCube()事件,并考虑将TabEngy提供给LI本身。此外,使按钮的测试依赖于状态变量,该变量是在选项之间切换时设置的。下面是一个工作示例Javascript 如何选择<;李>;在reactjs的按钮范围中,下拉列表,javascript,html,reactjs,drop-down-menu,Javascript,Html,Reactjs,Drop Down Menu,没用。如何处理此代码?也许使用TabCydiy='1,2,3/P>>P>使用OnFooCube()事件,并考虑将TabEngy提供给LI本身。此外,使按钮的测试依赖于状态变量,该变量是在选项之间切换时设置的。下面是一个工作示例 userevent =(event)=>{ console.log(event) } {this.state.selected} {this.setState({selected:e.target.value}}}>1.select {this.set
userevent =(event)=>{
console.log(event)
}
{this.state.selected}
- {this.setState({selected:e.target.value}}}>1.select
- {this.setState({selected:e.target.value}}}>{console.log(e.target.parentElement.value)}>2.select
- {this.setState({selected:e.target.value}}}>3.select
- {this.setState({selected:e.target.value}}}>4.select
这些是我所做的更改:1.将Tabindex从a移动到li。
2.将按钮中的文本替换为此.state.selected
3.向每个li添加了onFocus事件处理程序
您可以进一步重构它。不要忘记在构造函数中设置初始状态
userevent =(event)=>{
console.log(event)
}
<div className="input-group-btn" data-dropdown>
<button className="btn btn-default dropdown-toggle" type="button"
data-toggle="dropdown" aria-expanded="true">
<span id="sortevent1" tabindex="0">{this.state.selected}</span><span
id="arrow" className="glyphicon glyphicon-align-center"></span>
</button>
<ul className="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation" tabindex="1" onFocus={(e)=>{this.setState({selected:e.target.value})}}><a role="menuitem" >1.select <span id="arrow-up"
className="glyphicon glyphicon-indent-right"></span></a>
</li>
<li role="presentation" tabindex="2" onFocus={(e)=>{this.setState({selected:e.target.value})}}><a role="menuitem" onFocus={(e)=>{console.log(e.target.parentElement.value)}}>2.select <span id="arrow-down"
className="glyphicon glyphicon-indent-left"></span></a>
</li>
<li role="presentation" tabindex="3" onFocus={(e)=>{this.setState({selected:e.target.value})}}><a role="menuitem" >3.select <span id="arrow-up"
className="glyphicon glyphicon-indent-right"></span></a>
</li>
<li role="presentation" tabindex="4" onFocus={(e)=>{this.setState({selected:e.target.value})}}><a role="menuitem" >4.select <span id="arrow-up"
className="glyphicon glyphicon-indent-right"></span></a>
</li>
</ul>
</div>