【问题标题】:Can't get the selected text of Bootstrap Dropdown Menu with React+Jquery无法使用 React+Jquery 获取 Bootstrap 下拉菜单的选定文本
【发布时间】:2019-01-17 07:58:15
【问题描述】:

这是一个下拉菜单的 Bootstrap 4 代码:

<div className="btn-group show">
  <button className="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" data-type="fontFamily" style="width: 100px;">Avenir Next</button>
  <div className="dropdown-menu">
       <a className="dropdown-item" href="#" style="font-family: &quot;Avenir Next&quot;;">Avenir Next</a><a className="dropdown-item" href="#" style="font-family: Baghdad;">Baghdad</a>
       <a className="dropdown-item" href="#" style="font-family: Helvetica;">Helvetica</a><a class="dropdown-item" href="#" style="font-family: Monotype;">Monotype</a>
       <a className="dropdown-item" href="#" style="font-family: &quot;Times New Roman&quot;;">Times New Roman</a>
       <a className="dropdown-item" href="#" style="font-family: &quot;Lucida Grande&quot;;">Lucida Grande</a>
  <div className="dropdown-divider"></div>
       <a className="dropdown-item" href="#" style="font-family: &quot;Lucida Grande&quot;;">Lucida Grande</a>
 </div>

这是反应部分:

componentDidMount(){

  $('.dropdown-item').click((e) => {
      console.log('text', $(e.currentTarget).text());
   });

}

单击下拉菜单时,什么也没有发生。我不知道为什么。

请帮忙

【问题讨论】:

    标签: jquery reactjs drop-down-menu bootstrap-4


    【解决方案1】:

    class="..." 应该是 className="..." 假设您使用的是 JSX。

    还引出了你为什么使用 jquery + React 的问题......

    【讨论】:

    • 对不起,我弄错了,我刚刚编辑了我的帖子。它是“className”而不是“class”。由于fabricJS,我也使用jQuery。这个块实际上来自 fabriceJs 代码,在我的情况下只适用于 jQuery
    猜你喜欢
    • 2016-04-15
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多