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背包,但如果按常规的方法解决时间复杂 ...
随机推荐
- 让我们一起学习《Node.js入门》一书吧!
Node.js入门 读完本书之后,你将完成一个完整的web应用,该应用允许用户浏览页面以及上传文件. 里面对一些知识的讲解,让你略窥Node.js的门径.最好一段代码一段代码的写下来,我的习惯是手里拿 ...
- Array和ArrayList互相转换
class Order{ public string orderId; public string orderName; public decimal orderPrice; } public cla ...
- 记Flume-NG一些注意事项(不定时更新,欢迎提供信息)
这里只考虑flume本身的一些东西,对于JVM.HDFS.HBase等得暂不涉及.... 一.关于Source: 1.spool-source:适合静态文件,即文件本身不是动态变化的: 2.avro ...
- 最近打算体验一下discuz,有不错的结构化数据插件
提交sitemap是每位站长必做的事情,但是提交到哪里,能不能提交又是另外一回事.国内的话百度是大伙都会盯的蛋糕,BD站长工具也会去注册的,可有些账号sitemap模块一直不能用,或许是等级不够,就像 ...
- cocos基础教程(5)数据结构介绍之cocos2d::Vector
cocos2d::Vector cocos2d::Vector<T>是一个封装好的能动态增长顺序访问的容器.cocos2d::Vector<T>中的元素是按序存取的,它的低层实 ...
- svn报错 400 Bad Request
MyEclipse中的svn,commit经常报错 Error: Commit failed (details follow): Error: At least one property chang ...
- DrawText
该函数在指定的矩形里写入格式化的正文,根据指定的方法对正文格式化(扩展的制表符,字符对齐.折行等). int DrawText(HDC hDC, // 设备描述表句柄 LPCTSTR lpStri ...
- MySQL查询测试经验
测试表geoinfo,整个表超过1100万行,表结构: CREATE TABLE `geoinfo` ( `objectid` ) NOT NULL AUTO_INCREMENT , `latitud ...
- java中四种阶乘的计算
package com.zf.s2;//创建一个包 import java.math.BigInteger;//导入类 import java.util.ArrayList; import jav ...
- 利用 Chromium Embedded Framework (CEF) 定制提取 Flash 视频的浏览器
功能介绍: 利用 CEF 分析网页源码, 提取 flash 视频的代码. 提取的视频代码 LoadString 和 JS 两种方式重新插入到浏览器. (CEF_3.2171.1979_win32 - ...