jQuery
jQuery
jQuery API (哪里不会点哪里)
jQuery 库 CDN加速
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/core.js"></script> </head> <body> </body> </html>
选择器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> </head> <body> <a href="" id="test-jquery">点击</a> <script> //选择器就是 CSS 选择器 $('#test-jquery').click(function () { alert('点击'); }) </script> </body> </html>
公式:$(selector).action()
$('p').click(); //标签选择器 $('#id').click(); //Id选择器 $('.class').click(); //类选择器
鼠标事件
//当网页加载完毕之后,响应事件 <script> $(function(){ }); </script>
操作DOM
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> </head> <body> <ul id="test-ul"> <li class="javascript">javascript</li> <li name="python">python</li> </ul> <script> $('#test-ul li[name = python]').text(); $('#test-ul').html(); console.log($('#test-ul li[name = python]').text()); console.log($('#test-ul').html()); </script> </body> </html>
节点文本操作
$('#test-ul li[name = python]').text(); //获得值 $('#test-ul li[name = python]').text('设置值'); //设置值 $('#test-ul').html(); //获得值 $('#test-ul').html('<text>123</text>'); //设置值
结果
元素的显示与隐藏
$('#test-ul li[name = python]').show() $('#test-ul li[name = python]').hide()
相关推荐
83510998 2020-08-08
tthappyer 2020-07-25
tztzyzyz 2020-07-05
87281248 2020-07-04
82244951 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
开心就好 2020-06-10
84483065 2020-09-11
85477104 2020-08-15
delmarks 2020-06-28
89510194 2020-06-27
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13