簡體   English   中英

無法使用React + Jquery獲得Bootstrap下拉菜單的選定文本

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

這是下拉菜單的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());
   });

}

單擊下拉菜單時,什么都沒有發生。 我不知道為什么

請幫忙

假設您使用的是JSX,則class="..."應為className="..."

也引起了一個問題,為什么你要使用jquery + React ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM