React中jquery引用


在React中引用Jquery比較好玩,獲取元素的數據更多

1.引入方法舉例:

 1 import $ from 'jquery';
 2 
 3 import { Button } from 'antd';
 4 
 5 class testJquery extends React.Component {
 6 
 7   constructor(props) {
 8     super(props);
 9 
10     this.selectElement = this.selectElement.bind(this);
11 
12   }
13 
14   render() {
15 
16     return(
17 
18       <div>
19 
20         <Button onClick={this.selectElement}>點擊一下</Button>
21 
22         <h4 className="text">這是:12</h4>
23 
24       </div>
25 
26     );
27 
28   }
29 
30   selectElement() {
31 
32     console.log('text對象:',$('.text'));
33 
34     console.log('text中的值:',$('.text')[0].textContent);
35 
36   }
37 
38 }
39 
40 export default testJquery;

 

 2.界面樣式

 

3. 控制台打印結果

 4.text對象部分屬性

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM