对象中保存了创建的DOM元素 22 var $p = $( " p我是段落/p " ); 23 console.log
就是一个用js的插件库 解决了原生dom的操纵的兼容性和代码量
使用前需要引入它的插件
以下例子以
jquery-1.12.4.js 这个版本为例
一:jquery入口函数的写法
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 <script src="js/jquery-1.12.4.js"></script> 7 <script> 8 // 1.第一种写法 9 $(document).ready(function () { 10 // alert("hello lnj"); 11 }); 12 13 // 2.第二种写法 14 jQuery(document).ready(function () { 15 // alert("hello lnj"); 16 }); 17 18 // 3.第三种写法(保举) 19 $(function () { 20 // alert("hello lnj"); 21 }); 22 23 // 4.第四种写法 24 jQuery(function () { 25 alert("hello lnj"); 26 }); 27 </script> 28 </head> 29 <body> 30 31 </body> 32 </html>
二:jquery斗嘴问题
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title></title> 6 <script src="js/jquery-1.12.4.js"></script> 7 <script> 8 // 1.释放$的使用权 9 // 注意点: 释放操纵必需在编写其它jQuery代码之前编写 10 // 释放之后就不能再使用$,改为使用jQuery 11 // jQuery道理.noConflict(); 12 // 2.自界说一个访谒标记 13 var nj = jQuery.noConflict(); 14 nj(function() { 15 alert("hello lnj"); 16 }); 17 </script> 18 </head> 19 <body></body> 20 </html>
三:jquery核心函数
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 <script src="js/jquery-1.12.4.js"></script> 7 <script> 8 // $();/jQuery道理();就代表挪用jQuery的核心函数 9 10 // 1.接收一个函数 11 $(function () { 12 alert("hello lnj"); 13 // 2.接收一个字符串 14 // 2.1接收一个字符串选择器 15 // 返回一个jQuery东西, 东西中生存了找到的DOM元素 16 var $box1 = $(".box1"); 17 var $box2 = $("#box2"); 18 console.log($box1); 19 console.log($box2); 20 // 2.2接收一个字符串代码片段 21 // 返回一个jQuery东西, 东西中生存了创建的DOM元素 22 var $p = $("<p>我是段落</p>"); 23 console.log($p); 24 $box1.append($p); 25 // 3.接收一个DOM元素 26 // 会被包装成一个jQuery东西返回给我们 27 var span = document.getElementsByTagName("span")[0]; 28 console.log(span); 29 var $span = $(span); 30 console.log($span); 31 }); 32 </script> 33 </head> 34 <body> 35 <div class="box1"></div> 36 <div id="box2"></div> 37 <span>我是span</span> 38 </body> 39 </html>
四:jquery东西
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30680.html