详解jquery选择器的原理
网络编程 2021-07-04 18:33www.168986.cn编程入门
这篇文章主要介绍了详解jquery选择器的原理的相关资料,就是jquery原型里面有一个init初始化的方法,将传入的值进行解析,比如传入的id还是class还是标签名,需要的朋友可以参考下
详解jquery选择器的原理
html部分
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <script src="js/minijquery.js"></script> </head> <body> <div class="one">1</div> <div class="two">2</div> </body> <script> var result = $("div"); console.log(result); alert($('div').size()); </script> </html> js
js部分
(function(){ //暴露外部的引用 var jQuery = window.jQuery = window.$ = function(selector){ return new jQuery.fn.init(selector); } //添加原型事件 jQuery.fn = jQuery.prototype = { // init:function(selector){ var element = document.getElementsByTagName(selector); Array.prototype.push.apply(this,element); return this; }, myjQuery:"the test one", length:0, size:function(){ return this.length; } } //将init的原型引用成jQuery的原型 jQuery.fn.init.prototype = jQuery.fn; })();
我用我的理解解释一下,就是jquery原型里面有一个init初始化的方法,将传入的值进行解析,比如传入的id还是class还是标签名。然后通过相应的方法返回数组型对象。既可以通过对象直接调用方法,也可以使用数组的length。
以上就是jQuery 原理的分析,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程