上两篇简单的介绍了jquery的一些知识,也模拟了一下jquery的调用方式,下面我们整点更像的,jquery不是使用#来指定Id吗,我们也来试试,给我们的TestClass类添加一个selector来存储我们要找的目标,并且添加一个val方法来获取值和赋值
改版的TestClass如下:
(function(){
TestClass=function (selector){
return new TestClass.fn.init(selector);
}
TestClass.fn=TestClass.prototype={
init:function(selector){
this.selector=selector;
return this;
},
val:function(value){
if(!(this.selector&&this.selector.indexOf("#")==0)){
return ;
}
var id=this.selector.substring(1);
var obj=document.getElementById(id);
if(!value){
return obj.value;
}else{
obj.value=value;
}
}
}
TestClass.fn.init.prototype=TestClass.fn;
var $=TestClass;
window.$=$;
window.TestClass=TestClass;
})()
alert($("#myinput1").val());
$("#myinput1").val("xxxtest");
上面的判断比jquery要少很多,满足基本功能,对于select等等这些元素,还需继续扩招下去,这个比较简单。
以上在IE和火狐都会通过。
现在总结一点东西:
- 1,之所以要用匿名函数是避免出现方法或者属性,变量与其他的重复,在这个 里面定义的函数,在外面是不能直接调用的。
- 2,大量利用js prototype属性,对扩展类的方法有很大作用,它是一个给类的对象添加方法的方法。
现在jquery有很多扩展出来的插件,为整个框架带来生机,这也是它成为霸主的利剑,下一篇面我们就看看是怎样扩展它的功能的。
分享到:
相关推荐
jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码...
NULL 博文链接:https://duyunfei.iteye.com/blog/857841
Jquery源码分析 清晰 Jquery源码分析 清晰 Jquery源码分析 清晰 Jquery源码分析 清晰
jquery1.2.6源码分析,其中里面含有源码详细的中文注释
锋利的jQuery 源码锋利的jQuery 源码锋利的jQuery 源码锋利的jQuery 源码锋利的jQuery 源码锋利的jQuery 源码
jquery源码分析,包括入口技术,选择器入口,以及在选择器使用的时候需要注意的优化思路
jQuery源码分析视频教程总计116课,按照jquery每个区段实现的内容,精确地讲解源码中是怎么实现我们开发中用到的jquery得方法的
jQuery源码分析系列.pdf
jquery最新源码jquery最新源码jquery最新源码
jQuery源码解读,jQuery源码解读
jquery源码 带格式 读了一遍挺不错了 在这分享了
Head First jQuery 中文版 源码
jQuery源码分析-插件
jQuery学习资料 锋利的Jquery 源码 锋利的Jquery 源码 锋利的Jquery 源码
最新的开发版jQuery源码。jquery-1.8.0.js
Jquery1.26版本的源码分析,pdf格式文档,相当清淅的书籍,前端开发者必看的类库书籍,...采用CSS方式查找Dim节点,jQuery类数组的分析,Dom元素的属性及操作,Event事件分析及应用,jquery中的Ajax实现及源码分析等内容.
jquery框架源码,web前端开发框架
jquery 源码分析