简体   繁体   English

无法使用React + Jquery获得Bootstrap下拉菜单的选定文本

[英]Can't get the selected text of Bootstrap Dropdown Menu with React+Jquery

Here is a Bootstrap 4 code of a dropdown menu: 这是下拉菜单的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>

Here is the react part : 这是反应部分:

componentDidMount(){

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

}

When clicking on a dropdown, nothing happen. 单击下拉菜单时,什么都没有发生。 I don't know why. 我不知道为什么

Please help 请帮忙

class="..." should be className="..." assuming you're using JSX. 假设您使用的是JSX,则class="..."应为className="..."

also begs the question why you're using jquery + React... 也引起了一个问题,为什么你要使用jquery + React ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM