惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
The GitHub Blog
The GitHub Blog
腾讯CDC
GbyAI
GbyAI
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
B
Blog RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
AWS News Blog
AWS News Blog
S
Schneier on Security
P
Proofpoint News Feed
C
Check Point Blog
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
T
The Exploit Database - CXSecurity.com
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
T
Tenable Blog
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
C
Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
F
Full Disclosure
L
LINUX DO - 热门话题
博客园 - Franky
K
Kaspersky official blog
C
Cyber Attacks, Cyber Crime and Cyber Security
U
Unit 42
Recorded Future
Recorded Future
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Project Zero
Project Zero
F
Fortinet All Blogs
O
OpenAI News
Recent Announcements
Recent Announcements

博客园 - dail

IE浏览器在虚拟机中无法正常显示字符 jQuery在updatepanel中使用造成内存泄露 在使用jQuery的时候不小心的内存泄漏 jQuery 1.7的隐藏改动 在javascript中实现类似asp.net webcontrol中的render的方法 jQuery 1.6的变化 jQuery ui effects - dail jQuery ui 1.8.6 position 的一个bug 一个progressbar widget jquery animate动画的特殊用法。 一个简单的widget Jquery ui widget中的_create(),_init(),destroy() Jquery ui widget开发 Jquery ui css framework jquery animate Json.net简单用法 EXTJS学习(二)Message EXTJS学习(一) jquery+linq制作博客(二)
jQuery编写widget的一些窍门
dail · 2010-10-27 · via 博客园 - dail
  1. 在编写widget的时候,一般我们需要绑定一些事件,最好将这些widget的绑定事件加上当前widget的命名空间。如果同一个jQuery对象,使用了两个widget,而两个widget都绑定了相同的事件名称,可能会出现问题。在销毁widget的时候,去除绑定事件也很方便,只需要unbind(”.namespace“)就可以了。
  2. 在写jQuery的时候,因为jQuery对象是支持连写的。譬如:$(obj).css("height","20px").attr("title","abc")....
  3. 在编写的时候可以利用javascript的原生方法来避免switch。

    switch(a)
    {
      
    case "aa":
        
    this._set_aa();
        
    break;
      
    case "bb":
        this._set_bb();
        break;
      case "cc"
        this._set_cc();
        break;
    }

    上面的代码可以用下面的代码替换
     
  4. 尽量缓存jQuery对象,和各种变量。这样可以提高脚本的性能
  5. 采用变量缓存this指针,在最小化代码的时候this可以被最小化掉。
  6. 最好将css类名取一致的名称,然后定义变量保存起来。在使用的时候直接采用变量,这样就算css名称有调整,只需要改变变量缓存的值即可。同时代码在最小化的时候也能减小体积。
  7. setOption的时候,如果一个option是复杂对象,而不是简单的值对象,最好不要简单的this.options[key]=value.而在这之前需要将value和以前的option的值做一个extend,然后在赋值,这样可以保留复杂对象原有的部分值。比如:

    var a = {width:120,height:200};
    var c={width:200};
    a
    =c;
    a
    =$.extend(a,c);

     其结果是第一个a将是{width:20},会丢失掉height:200;而下面的那个将继续保留原始的height:200。

posted @ 2010-10-27 14:31  dail  阅读(3308)  评论()    收藏  举报