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背包,但如果按常规的方法解决时间复杂 ...
随机推荐
- editplus快捷键大全之editplus文件快捷键
editplus快捷键大全之editplus文件快捷键 新建普通文本 Ctrl+N 新建普通的文本文档 新建浏览器窗口 Ctrl+Shift+B 新建浏览器窗口 新建 HTML 页 Ctrl+Shif ...
- MySQL5.5 RPM安装的默认安装路径
MySQL5.5 RPM安装的默认安装路径 2011-06-20 10:34:32| 分类: MySQL|举报|字号 订阅 下载LOFTER客户端 由于一客户要求安装mysql- 5.5 ...
- 【SpringMVC】SpringMVC系列10之视图与视图解析器
10.视图与视图解析器 10.1.概述 请求处理方法执行完成后,最终返回一个 ModelAndView处理方法,Spring MVC 也会在内部将它们装配成一个ModelAndView 对象, ...
- codeigniter 视图
2014年7月7日 15:23:05 ci的视图功能很棒, 比如一个网页有四个部分组成,对应4个文件:header.php, sider.php, maincontent.php, footer .p ...
- Java for LeetCode 045 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- mybatisforeach循环,传入多个参数
上代码: controller: @RequestMapping(value = "/findPage", method = RequestMethod.POST) @Respon ...
- 【leetcode】clone-graph
写在前面的话: 看了看自己的博客,从一月底开始就没怎么更新过,我也确实将近5个月没怎么写代码了.今天突然觉得有些心慌,感觉手都已经生疏了.果然,随便找了道题就卡住了.隐约感觉要用map但又不太记得用法 ...
- KMP模式匹配练习题
使用KMP算法在文本串S中找模式串P是一种常见的方法.假设S=P={xyxyyxxyx},亦即将S对自己进行匹配,匹配过程中正确的next数组是____. 1.首先求最大相同前缀后缀长度 模式串的各个 ...
- MySQL错误:Every derived table must have its own alias
Every derived table must have its own alias 派生表都必须有自己的别名 一般在多表查询时,会出现此错误. 因为,进行嵌套查询的时候子查询出来的的结果是作为一个 ...
- Linux防火墙规则的查看、添加、删除和修改
这里只列出比较常用的参数,详细的请查看man iptables 1.查看 iptables -nvL –line-number -L查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表 ...