jquery-2  jQuery原理和核心方法(多看学习视频)

一、总结

一句话总结:jQuery就是普通的js对象,只不过方法比较多而已,属性就length一个。

1、jquery的链式操作的底层原理是什么?

一个方法执行完之后返回本身对象

28     obj.say=function(){
29 alert('my name is :'+this.username);
30 return this;
31 }
40 // 对象链式结构
41 $('imgid').say().eat();

2、所有链式操作的原理是什么(jquery,thinkphp)?

方法执行完返回对象

3、jquery函数体中和js函数体中地位是否一样?

完全一样,jquery只不过是对js进行了一些轻量级的封装而已

21 <script>
22 imgobj=document.getElementById('imgid');
23 // imgobj.onclick=function(){
24 // this.src='b.png';
25 // }
26
27 $(imgobj).click(function(){
28 this.src='b.png';
29 });
30 </script>

4、dom对象如何转成jquery对象?

在dom对象上面加上$(),$(dom)

5、this对象和$(this)的区别?

两者都是指向当前对象,只不过this对象是dom对象,$(this)是jquery对象,区别是dom对象指行dom的方法,jquery对象执行jquery的方法

6、jquery选择器选择出来的东西的本质是什么,比如$('h1')?

dom对象数组,而这个dom对象数组是一个jquery对象,所以jquery选择器选出来的东西都可以执行jquery的方法,并且加上下标能转化为dom对象

23 val=$('h1')[1].outerHTML;

7、jquery对象(本质是dom对象列表)如何转化成dom对象?

$('h1')[1];
$('h1').get(1);

23 val=$('h1').get(1).outerHTML;

8、jquery的get()方法得到的是什么,比如$('h1').get()?

dom对象数组

22 <script>
23 arr=$('h1').get();
24 alert(arr[0].outerHTML);
25 alert(arr[1].outerHTML);
26 </script>

9、jquery中的唯一属性?

length

10、jquery中获取jquery对象的两种方法?

size()方法和length属性

11、jquery中attr()方法的实质是什么?

js中的setAttribute()和getAttribute

26 $('h1').each(function(i){
27 $('h1').get()[i].setAttribute('num',i+1);
28 });
29
30 $('h1').click(function(){
31 this.innerHTML=this.getAttribute('num');
32 });

12、each方法作用?

因为jquery对象多为dom的数组,所以就是遍历

26 $('h1').each(function(i){
27 $(this).attr({'num':i+1});
28 });

13、jquery如何获取当前元素的索引值?

index方法

76     idx=$(this).index('.menu li');

14、jquery除什么之外的方法?

not方法

79     $('.info p').not($('.info p').eq(idx)).hide();

15、js对象和jquery对象的区别是什么?

jquery就是js中的new Object生成的普通对象

16、js对象和jquery对象的方法能不能共用?

不能共用

17、js对象和jquery对象能不能互换?(能)

1.js对象->jquery对象
$(dom);

2.jquery对象->js对象
$('h1')[1];
$('h1').get(1);

18、jquery核心方法有哪些?

size();
length;
get();
get(index);
each();
index();
data();

二、jQuery原理和核心方法

1、相关知识点

jQuery框架:
1.js对象和jquery对象的区别
2.js对象和jquery对象的转换
3.核心方法
4.选择器
5.筛选
6.属性选择器
7.文档处理
8.CSS处理
9.事件
10.效果
11.Ajax无刷新
12.工具

js对象和jquery对象的区别是什么?
jquery就是js中的new Object生成的普通对象

js对象和jquery对象的方法能不能共用?
不能共用

js对象和jquery对象能不能互换?(能)
1.js对象->jquery对象
$(dom);

2.jquery对象->js对象
$('h1')[1];
$('h1').get(1);

核心方法:
size();
length;
get();
get(index);
each();
index();
data();

2、代码

jquery对象原型开发

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaa</h1>
</body>
<script>
function $(attr){
obj=new Object();
obj.username='user123';
obj.say=function(){
alert('my name is :'+this.username);
return this;
} obj.eat=function(){
alert('my am eating!');
} return obj;
} // 对象链式结构
$('imgid').say().eat();
</script>
</html>

把dom对象转成jquery对象

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<img src="a.png" id="imgid">
</body>
<script>
imgobj=document.getElementById('imgid');
// imgobj.onclick=function(){
// this.src='b.png';
// } $(imgobj).click(function(){
this.src='b.png';
});
</script>
</html>

js对象和jquery对象互换

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<img src="a.png" id="imgid">
</body>
<script>
imgobj=document.getElementById('imgid'); $(imgobj).click(function(){
this.src='b.png';
// $(this).attr({'src':'b.png'});
});
</script>
</html>

jquery对象转成js对象

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>bbbbbbbbbbbbbbbbbbb</h1>
</body>
<script>
val=$('h1')[].outerHTML;
alert(val);
</script>
</html>

jquery对象转成js对象2

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>bbbbbbbbbbbbbbbbbbb</h1>
</body>
<script>
val=$('h1').get(1).outerHTML;
alert(val);
</script>
</html>

把jquery对象转成js对象数组

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>bbbbbbbbbbbbbbbbbbb</h1>
</body>
<script>
arr=$('h1').get();
alert(arr[0].outerHTML);
alert(arr[1].outerHTML);
</script>
</html>

size和length获取jquery对象中dom对象的个数

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>bbbbbbbbbbbbbbbbbbb</h1>
</body>
<script>
alert($('h1').size());
alert($('h1').length);
</script>
</html>

单击换行号

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
</body>
<script>
$('h1').each(function(i){
$('h1').get()[i].setAttribute('num',i+1);
}); $('h1').click(function(){
this.innerHTML=this.getAttribute('num');
});
</script>
</html>

each遍历jquery对象

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
</body>
<script>
$('h1').each(function(i){
$(this).attr({'num':i+1});
}); $('h1').click(function(){
$(this).html($(this).attr('num'));
});
</script>
</html>

index搜索匹配的元素,并返回相应元素的索引值

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
margin:0px;
padding:0px;
} .menu{
height:50px;
background: #272822;
line-height: 50px;
} .menu ul{
list-style:none;
} .menu ul li{
float: left;
color:#fff;
margin-left:15px;
line-height: 50px;
width:100px;
text-align:center;
} .menu ul li:hover{
cursor: pointer;
background: #ccc;
} .info{
height:200px;
background: #ccc;
overflow: hidden;
padding:15px;
} .info p{
display: none;
} .info p:first-child{
display: block;
} .menu a:hover{
background: #ccc;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div class='menu'>
<ul>
<li>linux</li>
<li>php</li>
<li>javascript</li>
</ul>
</div> <div class='info'>
<p>linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!</p> <p>php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!</p>
<p>javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!</p>
</div>
</body>
<script>
$('.menu li').mouseenter(function(){
idx=$(this).index('.menu li'); $('.info p').eq(idx).show();
$('.info p').not($('.info p').eq(idx)).hide();
});
</script>
</html>

酒仙网上标签页效果

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
margin:0px;
padding:0px;
} .menu{
height:50px;
background: #272822;
line-height: 50px;
} .menu ul{
list-style:none;
} .menu ul li{
float: left;
color:#fff;
margin-left:15px;
line-height: 50px;
width:100px;
text-align:center;
} .menu ul li:hover{
cursor: pointer;
background: #ccc;
} .info{
height:200px;
background: #ccc;
overflow: hidden;
padding:15px;
} .info p{
display: none;
} .info p:first-child{
display: block;
} .menu a:hover{
background: #ccc;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div class='menu'>
<ul>
<li>linux</li>
<li>php</li>
<li>javascript</li>
</ul>
</div> <div class='info'>
<p>linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!linux is very much!</p> <p>php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!php is very much!</p>
<p>javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!javascript is very much!</p>
</div>
</body>
<script>
$('.menu li').eq(0).css({'background':'#ccc'}); $('.menu li').mouseenter(function(){
$(this).css({'background':'#ccc'});
$('.menu li').not($(this)).css({'background':'#272822'}); idx=$(this).index('.menu li'); $('.info p').eq(idx).show();
$('.info p').not($('.info p').eq(idx)).hide();
});
</script>
</html>

data往jquery对象身上赋值

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
} select{
width:100px;
height:150px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
</body>
<script>
$('h1').each(function(i){
$(this).data({'num':i+1});
}); $('h1').click(function(){
$(this).html($(this).data('num'));
});
</script>
</html>
 

jquery-2 jQuery原理和核心方法(多看学习视频)的更多相关文章

  1. JM-2 jQuery Mobile的使用(多看学习视频)

    JM-2 jQuery Mobile的使用(多看学习视频) 一.总结 一句话总结:前端框架的使用全都一个样,本质都是css和js,引入文件也是这些.使用都是看手册,超简单. 1.jQuery Mobi ...

  2. <a href='javacript:' title='{$str}'>是什么意思(多看学习视频)

    <a href='javacript:' title='{$str}'>是什么意思(多看学习视频) 一.总结 一句话总结: 1.javascript:是什么? 伪协议,后面接javascr ...

  3. php课程 4-15 数组遍历、超全局数组、表单提交数据(多看学习视频)

    php课程 4-15  数组遍历.超全局数组.表单提交数据(多看学习视频) 一.总结 一句话总结:超全局数组特别有用,比如$_SERVER可以获取所有的客户端访问服务器的情况. 1.数组遍历三种方式( ...

  4. jQuery的实现原理和核心

    1.jQuery的实现原理 1)jQuery采用的是构造函数模式进行开发的,jQuery是一个类 2)上面说的常用的方法(CSS.属性.筛选.事件.动画.文档处理)都是定义在jQuery.protot ...

  5. jQuery编程中的一些核心方法简介

    调用 jQuery 对象的方法很简单: $('h1').remove(); 大多数 jQuery 方法都是像上面这样被调用的,这些方法都位于 $.fn 命名空间内,这些方法称为 jQuery 对象方法 ...

  6. jQuery源码分析_工具方法(学习笔记)

    expando:生成唯一JQ字符串(内部使用) noConflict():防止冲突 isReady:DOM是否加载完成(内部) readyWait:等待多少文件的计数器(内部) holdReady() ...

  7. 2018-08-26 jQuery与javaScript的区别及核心方法

    1.jq对象就是js new Object 生成的普通对象. 2.jq对象与js对象,他们的方法不能共用! 3.jq对象与js对象的相互转化: js对象转jq对象 -> $(js_obj);// ...

  8. jQuery 常用核心方法

    jQuery 常用核心方法 .each() 遍历一个jQuery对象,为每个匹配元素执行一个函数 $('p').each(function(idx,node){ $(node).text(idx + ...

  9. 解密jQuery内核 DOM操作的核心函数domManip

    domManip是什么 dom即Dom元素,Manip是Manipulate的缩写,连在一起就是Dom操作的意思. .domManip()是jQuery DOM操作的核心函数 对封装的节点操作做了参数 ...

随机推荐

  1. OC文件操作、获取文件属性

    #import <Foundation/Foundation.h> //获取文件的属性 int main(int argc, const char * argv[]) { @autorel ...

  2. CentOS卸载Apache方法

    https://www.kafan.cn/edu/49420412.html CentOS卸载Apache方法 首先关闭httpd服务 /etc/init.d/httpd stop 列出httpd相关 ...

  3. XAMPP各个版本配置

    XAMPP各个版本配置 http://code.stephenmorley.org/articles/xampp-version-history-apache-mysql-php/ XAMPP  Ap ...

  4. ua识别(浏览器标识识别)

    ua识别(浏览器标识识别) 一.总结 1.浏览器标识(UA):可以使得服务器能够识别客户使用的操作系统及版本.CPU 类型.浏览器及版本.浏览器渲染引擎.浏览器语言.浏览器插件,从而判断用户是使用电脑 ...

  5. 【编程】辨异 —— proxy 与 delegate

    二者分别对应着设计模式中的代理模式和委托模式. proxy:译为代理, 被代理方(B)与代理方(A)的接口完全一致. 主要使用场景(语义)应该是:为简化编程(或无法操作B),不直接把请求交给被代理方( ...

  6. docker构建一个简易镜像

    一 下载centos镜像 docker pull centos 二 启动镜像 [root@Centos-node3 ~]# docker run -it --name my_ng centos bas ...

  7. VC6.0调试知识大全

    VC6.0调试知识大全 分类: C++ 2010-09-06 21:33 7080人阅读 评论(5) 收藏 举报 debuggingmfcfunctionmenumicrosoftdll My Not ...

  8. AlertDialog的onCreateDialog与onPrepareDialog用法

    场景:在一个Activity中多次使用弹出对话框.而且对话框携带着动态变化的信息数据,这时假设仅仅使用onCreateDialog(int id, Bundle bundle)回调,则会发现第一次以后 ...

  9. ASM学习笔记--ASM 4 user guide 第一章翻译

    ASM是什么? 借用别人的话 :ASM 是一个 Java 字节码操控框架.它能被用来动态生成类或者增强既有类的功能. ASM 可以直接产生二进制 class 文件,也可以在类被加载入 Java 虚拟机 ...

  10. GOROOT,GOPATH,GOBIN,project

    GOROOT,GOPATH,GOBIN,project目录   我们接下来一个一个来看关于Go语言中的三个目录的详细解释先通过go env查看go的环境变量(我这里是mac的环境,所以可能和你的不同) ...