查找:

  • 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. 移动端学习系列1--meta标签

    <!-- 是否启动webapp功能,会删除默认的苹果工具栏和菜单栏 --><meta name="apple-mobile-web-app-capable" co ...

  2. 基于Redis的短链接设计思路

    [Markdown阅读][1] 今天上班的时候收到一个需要短链接的需求,之前的做法都是使用了新浪的短链接API(https://api.weibo.com/2/short_url/shorten.js ...

  3. Linux守护进程的启动方法

    导读 “守护进程”(daemon)就是一直在后台运行的进程(daemon),通常在系统启动时一同把守护进程启动起来,本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 Web应用写好后 ...

  4. each-Select

    While Ruby’s each method is useful, it also comes with an awesome extended family of methods that ar ...

  5. lvs之dr技术的学习与实践

    1.配置测试环境 修改IP windows 200.168.10.4 lvs server  ip:200.168.10.1 因为IP隧道模式只需要一个网卡  所以就停掉其他网卡 web server ...

  6. Bmob用户管理操作

    注册用户 BmobUser bu = new BmobUser(); bu.setUsername("sendi"); bu.setPassword("123456&qu ...

  7. C语言中%d,%o,%f,%e,%x的意义

    printf(格式控制,输出列表) 格式控制包括格式说明和格式字符. 格式说明由“%”和格式字符组成,如%d%f等.它的作用是将输出的数据转换为指定的格式输出.格式说明总是由“%”字符开始的.不同类型 ...

  8. django 1.7 新特性 --- data migration

    官方文档:https://docs.djangoproject.com/en/dev/topics/migrations/ 1.7 之前大家可能会用south用于管理数据库的模型的同步.1.7之后dj ...

  9. Java正则表达式的最简单应用

    String emailRegex = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; Pattern pat = ...

  10. 【云计算】Docker删除名称为none的Image镜像

    先上删除命令: docker images|grep none|awk '{print $3 }'|xargs docker rmi docker强制批量删除none的image镜像   真是有段时间 ...