如何在React中获取所选数据?

问题描述 投票:0回答:1

当我选择项目时,veri功能未运行。为什么不起作用,我该怎么办?

class User extends Component {

    veri = (e) => {                   //functions
        console.log(e.target.value)
    }

    render() {

        return (
            <div>

                <div className="container anaclass">
                     <div className="dropdown" style={{display:"inline"}}  >
                        <button className="btn btn-primary px-5" data-toggle="dropdown"  >ligler</button>

                        <div className="dropdown-menu" id="lig"  onChange={this.veri} >
                            <a href="" className="dropdown-item">İtalya</a>
                            <a href="" className="dropdown-item">İngiltere</a>
                            <a href="" className="dropdown-item">Almanya</a>
                        </div>
                    </div> 


                </div>

            </div>
        )
    }
reactjs
1个回答
0
投票

您可以检查console.log(e.target)以查看收到的内容。您应该使用onClick而不是onChange调用veri函数。

© www.soinside.com 2019 - 2024. All rights reserved.