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

推荐订阅源

V
Vulnerabilities – Threatpost
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
P
Palo Alto Networks Blog
大猫的无限游戏
大猫的无限游戏
量子位
S
Secure Thoughts
博客园 - 【当耐特】
V
Visual Studio Blog
腾讯CDC
爱范儿
爱范儿
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Latest news
Latest news
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Cloudbric
Cloudbric
T
Troy Hunt's Blog
S
Security @ Cisco Blogs
B
Blog RSS Feed
I
Intezer
S
SegmentFault 最新的问题
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
C
CXSECURITY Database RSS Feed - CXSecurity.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
TaoSecurity Blog
TaoSecurity Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recorded Future
Recorded Future
Google DeepMind News
Google DeepMind News
Forbes - Security
Forbes - Security
雷峰网
雷峰网
博客园 - 司徒正美
C
Cisco Blogs
S
Securelist
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
N
News | PayPal Newsroom
N
News and Events Feed by Topic

博客园 - 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编写widget的一些窍门 jquery animate动画的特殊用法。 Jquery ui widget中的_create(),_init(),destroy() Jquery ui widget开发 Jquery ui css framework jquery animate Json.net简单用法 EXTJS学习(二)Message EXTJS学习(一) jquery+linq制作博客(二)
一个简单的widget
dail · 2010-06-29 · via 博客园 - dail

这里是一个简单的widget,在代码里也写了注释。

代码

//此widget是将textbox进行修饰一下的。自身没有css,采用的是jquery ui css framework的样式
(function($){
//ui默认采用jquery的ui前缀,后面的是widget名称
    $.widget("ui.textboxdecorator", {
//此widget中没有options
        options:{
        },
        _init: 
function(){
            
//验证是否是需要装饰的元素
            
            
if (!(this.element.attr("tagName").toLowerCase() === "input" || this.element.attr("tagName").toLowerCase() === "textarea")) {
                
return;
            }
            
if (!(this.element.attr("type").toLowerCase() === "text" || this.element.attr("type").toLowerCase() === "password")) {
                
if (this.element.attr("tagName").toLowerCase() === "input"
                    
return;
            }
//this.element也就是调用此widget的元素
            var e = this.element;
//ui-widget widget基本的样式,ui-state-default。默认状态的样式;ui- corner-all 圆角(基于css3,ie下不起作用)
            this.element.addClass("ui-widget ui-state-default ui-corner-all");
            
//添加hover效果和active效果
                        this.element.mouseover(function(){
                e.addClass(
"ui-state-hover");
            }).mouseout(
function(){
                e.removeClass(
"ui-state-hover");
            }).mousedown(
function(){
                e.addClass(
"ui-state-active");
            }).mouseup(
function(){
                e.removeClass(
"ui-state-active");
            });
        },
//销毁时,移除widget增加的样式
        destroy:function(){
            
this.element.removeClass("ui-widget ui-state-default ui-corner-all ui-state-hover ui-state-active");
        }        
    })
})(jQuery)

在使用该widget的时候,需要引用jquery,jquery.ui.core.js,jquery.ui.widget.js文件,css文件需要jquery.ui.core.css和jquery.ui.theme.css两个文件

在调用的时候采用$("***"). textboxdecorator();来调用此widget。