jquery-2 jQuery原理和核心方法(多看学习视频)
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原理和核心方法(多看学习视频)的更多相关文章
- JM-2 jQuery Mobile的使用(多看学习视频)
JM-2 jQuery Mobile的使用(多看学习视频) 一.总结 一句话总结:前端框架的使用全都一个样,本质都是css和js,引入文件也是这些.使用都是看手册,超简单. 1.jQuery Mobi ...
- <a href='javacript:' title='{$str}'>是什么意思(多看学习视频)
<a href='javacript:' title='{$str}'>是什么意思(多看学习视频) 一.总结 一句话总结: 1.javascript:是什么? 伪协议,后面接javascr ...
- php课程 4-15 数组遍历、超全局数组、表单提交数据(多看学习视频)
php课程 4-15 数组遍历.超全局数组.表单提交数据(多看学习视频) 一.总结 一句话总结:超全局数组特别有用,比如$_SERVER可以获取所有的客户端访问服务器的情况. 1.数组遍历三种方式( ...
- jQuery的实现原理和核心
1.jQuery的实现原理 1)jQuery采用的是构造函数模式进行开发的,jQuery是一个类 2)上面说的常用的方法(CSS.属性.筛选.事件.动画.文档处理)都是定义在jQuery.protot ...
- jQuery编程中的一些核心方法简介
调用 jQuery 对象的方法很简单: $('h1').remove(); 大多数 jQuery 方法都是像上面这样被调用的,这些方法都位于 $.fn 命名空间内,这些方法称为 jQuery 对象方法 ...
- jQuery源码分析_工具方法(学习笔记)
expando:生成唯一JQ字符串(内部使用) noConflict():防止冲突 isReady:DOM是否加载完成(内部) readyWait:等待多少文件的计数器(内部) holdReady() ...
- 2018-08-26 jQuery与javaScript的区别及核心方法
1.jq对象就是js new Object 生成的普通对象. 2.jq对象与js对象,他们的方法不能共用! 3.jq对象与js对象的相互转化: js对象转jq对象 -> $(js_obj);// ...
- jQuery 常用核心方法
jQuery 常用核心方法 .each() 遍历一个jQuery对象,为每个匹配元素执行一个函数 $('p').each(function(idx,node){ $(node).text(idx + ...
- 解密jQuery内核 DOM操作的核心函数domManip
domManip是什么 dom即Dom元素,Manip是Manipulate的缩写,连在一起就是Dom操作的意思. .domManip()是jQuery DOM操作的核心函数 对封装的节点操作做了参数 ...
随机推荐
- vue的mode: 'history'模式
const router = new VueRouter({ mode: 'history', routes: [...] }) 不用mode: 'history'的时候,页面url地址后面会加上一个 ...
- LinearLayout-layout_gravity 属性没有效果分析
今天在一个布局文件中,遇到了一个问题,先看代码 <LinearLayout android:layout_width="match_parent" android:layou ...
- Excel数据比对-批量数据比对
1.导出现场的Excel收费规则2.有专门的代码写的测试收费规则的工具(开发自己开发的)3.在这个工具上选择,导出的收费规则Excel,点击导出按钮(导出按钮里面有计算每一列的计费结果4.Excel里 ...
- Java Web学习总结(16)——JSP的九个内置对象
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- 最大似然 vs. 最小二乘
有一篇是比较最大似然估计和最小二乘法的: http://www.cnblogs.com/hxsyl/p/5590358.html 最大似然估计:现在已经拿到了很多个样本(你的数据集中所有因变量),这些 ...
- [转]C#连接操作mysql实例
本文转自:http://hi.baidu.com/zhqngweng/item/c4d2520cb7216877bfe97edf 第三方组件:Mysql.Data.dll说明:去官方网站下载Mysql ...
- GPUImage ==> 一个基于GPU图像和视频处理的开源iOS框架
Logo 项目介绍: GPUImage是Brad Larson在github托管的开源项目. GPUImage是一个基于GPU图像和视频处理的开源iOS框架,提供各种各样的图像处理滤镜,并且支持照相机 ...
- netty reactor线程模型分析
netty4线程模型 ServerBootstrap http示例 // Configure the server. EventLoopGroup bossGroup = new EpollEvent ...
- ORA-00119: invalid specification for system parameter LOCAL_LISTENER;
错误提示内容及上下文环境: SQL> grant sysdba to weng;grant sysdba to weng*第 1 行出现错误:ORA-01034: ORACLE not avai ...
- FPGA实现UHS的一些资料
对使用FPGA和SD卡进行UHS模式通信的评估: 论文:基于FPGA的SD UHS-II卡控制器设计与实现 设计IP:SD UHS-II Host Controller 供应商: System Lev ...