donghongbz 2020-02-19
jQuery API (哪里不会点哪里)
<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>
<!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()