查找:

  • 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() {});

  • after()   //与remove一起用节点替换

    • --->

        $("#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");
    });

事件:

  • 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的更多相关文章

  1. 新手必看的jQuery优化笔记十则

    jQuery优化 1.简介 jQuery正在成为Web开发人员首选的JavaScript库,作为Web开发者,除了要了解语言和框架的应用技巧外,如何提升语言本身的性能也是开发人员应该思考的问题.文章就 ...

  2. jquery优化引发的思考

    无意间看到jquery优化的一个细节让我觉得不可思议记录一下.仅仅只是换个地方代码就能提高数倍的效率,带给我的不是个仅是个小技巧,而是一总编程思想,技术大牛往往是在细节上体现. 通过缓存最小化选择操作 ...

  3. jquery优化28个建议

    我一直在寻找有关jQuery性能优化方面的小窍门,能让我那臃肿的动态网页应用变得轻便些.找了很多文章后,我决定将最好最常用的一些优化性能的建议列出来.我也做了一个jQuery性能优化的简明样式表,你可 ...

  4. jquery优化轮播图2

    继续优化 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  5. jquery优化

    选择器优化执行的速度 选择器 优先:id>元素>类 使用对象缓存:即使用变量来保存对象名,var $myDiv = $("#myDiv"):$myDiv.show(); ...

  6. jQuery优化性能的十种方法

    1,总是从ID选择器开始继承 例如: <div id="content"> <form method="post" action=" ...

  7. jquery优化02

    缓存变量:DOM遍历是昂贵的,所以尽量将会重用的元素缓存. $element = $('#element'); h = $element.height(); //缓存 $element.css('he ...

  8. ☀【jQuery 优化】jQuery基础教程(第3版)

    jQuery代码优化:选择符篇 √ http://www.ituring.com.cn/article/377 jQuery代码优化:遍历篇 √ http://www.ituring.com.cn/a ...

  9. HDU 3732 Ahui Writes Word 多重背包优化01背包

    题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...

随机推荐

  1. NGUI 图集生成 图片Sprite 有撕裂边的问题

    修改 Dimensions 的 X 和 Y值进行调整. 在生成图集时 选择Padding 设置1以上 应该不会出现这个问题.

  2. UIImageView 动画 / UIImage 方向

    UIImage 方向 UIImage imageOrientation是相对当前屏幕的横竖屏来判断方向 如果本身是横屏, 照片也是横屏的话, 方向是正方向 BOOL b1 = (originalIma ...

  3. 对大一新生开始学习C语言课程谈几点看法

    大家好,首先祝贺大家进入了大学,迈入了大学的校门,也意味着开始了新的征程,希望大家能够有一个美好的大学四年. 先做下自我介绍,我叫李帅阳,(大家可以称呼我 李老师,或是班助,或是...)这是在邹欣老师 ...

  4. CreateRemoteThread远程线程注入Dll与Hook

    CreateRemoteThread虽然很容易被检测到,但是在有些场合还是挺有用的.每次想用的时候总想着去找以前的代码,现在在这里记录一下. CreateRemoteThread远程注入 DWORD ...

  5. Python Template 错误

    ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is und ...

  6. 【OpenStack】OpenStack系列1之OpenStack本地开发环境搭建&&向社区贡献代码

    加入OpenStack社区 https://launchpad.net/,注册用户(597092663@qq.com/Admin@123) 修改个人信息,配置SSH keys.OpenPGP keys ...

  7. vs2013秘钥

    Ultimate:BWG7X-J98B3-W34RT-33B3R-JVYW9 Premium:FBJVC-3CMTX-D8DVP-RTQCT-92494  YKCW6-BPFPF-BT8C9-7DCT ...

  8. h5在微信中不允许放大缩小页面

    在头部添加 <meta name="viewport" content="width=device-width, initial-scale=1, maximum- ...

  9. 如何在android的mk文件添加依赖已经编译好的库

    用$(MY_LIB)是代表你的库的所在目录,目录结构是这样 MY_LIB |---include |-----xxx.h |-----xxx.h |---lib |----MYLIB.a LOCAL_ ...

  10. poj 1625 (AC自动机好模版,大数好模版)

    题目 给n个字母,构成长度为m的串,总共有n^m种.给p个字符串,问n^m种字符串中不包含(不是子串)这p个字符串的个数. 将p个不能包含的字符串建立AC自动机,每个结点用val值来标记以当前节点为后 ...