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

推荐订阅源

MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
C
Check Point Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
Vercel News
Vercel News
腾讯CDC
GbyAI
GbyAI
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件

博客园 - 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。