jquery优化01
查找:
- children: find(selector), children(selector);
- parent: parent(), parents(selector), closest(selector) //最近的上层
- find()
- $("#main li");$("#main > li"); ---> $("#main").find("li");$("#main").children('li');
- first()/last()
- $("#main li:first") ---> $("main").find("li").first(); /last()
- filter()
- $("#main.onsale"); ---> $("#main").filter(".onsale");
绑定:
- on(
$("button").click(function(event) {}); ---> $("button").on("click",function() {});
- --->
$("#div").on("click","button",function() {
var message = "<span>click now!</span>";
$(this).after(message).remove();
}); data() //HTML5属性,适用于文本的设置替换
<div data-title="use data">
<button id="set">set</button>
<button id="get">get</button>
</div>
----------------------------------
$("#set").on("click",function() {
$(this).parent().data("title","data has changed");
});
$("#get").on("click",function() {
$(this).after($(this).parent().data("title")).remove();
});- 使用namespace和off()
//of()
-------------------------
$("#btn1").on("click",picture);
$("#btn1").on("click",status);
$("#btn1").off("click"); //namespace
--------------------------
$("#btn2").on("click.pic",picture);
$("#btn2").on("click.stat",status);
$("#btn2").off("click.pic"); $("#btn3").on("click.pic",picture);
$("#btn3").on("click.stat",status);
$("#btn3").on("mouseover.stat",status);
$("#btn3").off(".stat"); - 使用trigger //触发
$("#btn4").on("click",function() {
$("#btn2").trigger("click");
}); $("div").on("exam.new",function() { //自定义
console.log($(this).data());
});
$("#btn5").on("click.pict",function() {
picture();
$("div").trigger("exam.new");
});
after() //与remove一起用节点替换
事件:
- keyboard events: keypress,keydown,keyup;
- form events: focus,blur,change,select,submit;
- mouse events: click,dbclick,focusin,focusout,mousedowm,mouseup,mousemove,mouseout,mouseover,mouseleave,mouseenter;
节点与方法连接
function Confirmation(ele) {
this.ele = ele;
this.ticket = this.ele.find(".ticket");
var confirmation = this;
this.loadConfirmation = function() {
$.ajax("confirmation.html", {
timeoOut: 3000,
context: confirmation,//"this" in the function;
success: function(res) {
this.ticket.html(res).slideDown();
}
});
this.showBoardingPass = function(event) {
event.preventDefault();
$(this).hide();
confirmation.find(".boarding-pass").show();
};
this.ele.on("click","button",this.loadConfirmation);
this.ele.on("click","view-boarding-pass",this.showBoardingPass);
}
}
$(function() {
var paris = new Confirmation($("#paris"));
var london = new Confirmation($("#london"));
});
jquery优化01的更多相关文章
- 新手必看的jQuery优化笔记十则
jQuery优化 1.简介 jQuery正在成为Web开发人员首选的JavaScript库,作为Web开发者,除了要了解语言和框架的应用技巧外,如何提升语言本身的性能也是开发人员应该思考的问题.文章就 ...
- jquery优化引发的思考
无意间看到jquery优化的一个细节让我觉得不可思议记录一下.仅仅只是换个地方代码就能提高数倍的效率,带给我的不是个仅是个小技巧,而是一总编程思想,技术大牛往往是在细节上体现. 通过缓存最小化选择操作 ...
- jquery优化28个建议
我一直在寻找有关jQuery性能优化方面的小窍门,能让我那臃肿的动态网页应用变得轻便些.找了很多文章后,我决定将最好最常用的一些优化性能的建议列出来.我也做了一个jQuery性能优化的简明样式表,你可 ...
- jquery优化轮播图2
继续优化 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- jquery优化
选择器优化执行的速度 选择器 优先:id>元素>类 使用对象缓存:即使用变量来保存对象名,var $myDiv = $("#myDiv"):$myDiv.show(); ...
- jQuery优化性能的十种方法
1,总是从ID选择器开始继承 例如: <div id="content"> <form method="post" action=" ...
- jquery优化02
缓存变量:DOM遍历是昂贵的,所以尽量将会重用的元素缓存. $element = $('#element'); h = $element.height(); //缓存 $element.css('he ...
- ☀【jQuery 优化】jQuery基础教程(第3版)
jQuery代码优化:选择符篇 √ http://www.ituring.com.cn/article/377 jQuery代码优化:遍历篇 √ http://www.ituring.com.cn/a ...
- HDU 3732 Ahui Writes Word 多重背包优化01背包
题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...
随机推荐
- Minimum Inversion Number
Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- Swift Tour 随笔总结 (2)
Type Aliases typealias AudioSample = UInt16 Booleans 非boolean值不会被替代为bool,例如: let i = 1 if i { // thi ...
- raspberry树莓派安装CUPS实现打印服务器共享HP P1007打印机
虽然很多文章提到了raspberry树莓派如何安装cups实现共享打印机服务,但是我自己试下来发现HP P1007总是无法使用,折腾了很久,终于找到了方法,记录一下. 默认raspberry树莓派已经 ...
- NYOJ 61传纸条(一) 双线程DP问题
http://www.cnblogs.com/HpuAcmer/archive/2012/05/06/2486591.html 题目链接:http://acm.nyist.net/JudgeOnlin ...
- ubuntu下sh文件使用
可把shell命令批处理写进filename.sh文件 然后执行 chmod +x filename.sh 就可以执行./filename.sh了
- 【Hibernate】Hibernate系列2之Session详解
Session详解 2.1.概述-一级缓存 2.2.操作session缓存方法 2.3.数据库隔离级别 2.4.持久化状态 2.5.状态转换 2.6.存储过程与触发器
- MVC ViewBag和ViewData的区别
在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic),ViewData 是 ...
- Java for LeetCode 200 Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- 读取STL模型
读取二进制格式的STL模型文件 std::ifstream fin;fin.open(stlFilePath, std::ios::in | std::ios::binary);bool isBina ...
- CUDA学习笔记(三)——CUDA内存
转自:http://blog.sina.com.cn/s/blog_48b9e1f90100fm5f.html 结合lec07_intro_cuda.pptx学习 内存类型 CGMA: Compute ...