zoukankan      html  css  js  c++  java
  • jQuery按钮控件,转来的

    网上转来的,刚好能用到,不过要改造。先把原来的代码贴上做个记录,稍后整理。
     
    (function($){   
        $.fn.btn = function(){   
            var btn = this.data("_self");;   
            if(btn){   
                return btn;   
            };   
            this.init = function(){   
                var obj = $(this);   
                var id=$(this).attr('id')||"gen"+Math.random();   
                var icon = $(this).attr('icon')||'icon-btncom';   
                var bntStr=[   
                    '<table id="',id,'" class="z-btn" cellSpacing=0 cellPadding=0 border=0><tbody><tr>',   
                        '<TD class=z-btn-left><i>&nbsp;</i></TD>',   
                        '<TD class=z-btn-center><EM unselectable="on">',   
                            '<BUTTON class="z-btn-text ',icon,'" >',$(this).attr('value'),'</BUTTON>',   
                        '</EM></TD>',   
                        '<TD class=z-btn-right><i>&nbsp;</i></TD>',   
                    '</tr></tbody></table>'  
                ];   
                var bnt = $(bntStr.join('')).btn();   
                bnt._click = eval(obj.attr("onclick"));   
                bnt.disable();   
                if(obj.attr("disabled"))   
                    bnt.disable();   
                else bnt.enable();   
                $(this).replaceWith(bnt);   
                bnt.data("_self", bnt);     
                return bnt;   
            };   
            this.enable = function(){   
                this.removeClass("z-btn-dsb");   
                this.click(this._click);   
                this.hover(   
                      function () {   
                        $(this).addClass("z-btn-over");   
                      },   
                      function () {   
                        $(this).removeClass("z-btn-over");   
                      }   
                    )   
            };   
            this.disable = function(){   
                 this.addClass("z-btn-dsb");   
                 this.unbind("hover");   
                 this.unbind("click");   
            };     
            return this;   
        };   
           
        $(function(){   
            $("input[type='button']").each(function(){   
                $(this).btn().init();   
            });   
            $("input[type='reset']").each(function(){   
                $(this).btn().init().click(function(){   
                    var form = $(this).parents("form")[0];   
                    if(form)   
                        form.reset();   
                });   
            });   
            $("input[type='submit']").each(function(){   
                $(this).btn().init().click(function(){   
                    var form = $(this).parents("form")[0];   
                    if(form)   
                        form.submit();   
                });   
            });   
        })   
    })(jQuery);  
  • 相关阅读:
    ORM 实现数据库表的增删改查
    数据库表设计(一对多,多对多)
    Razor模板引擎
    文件的上传(表单上传和ajax文件异步上传)
    生成验证码封装(新版)
    MD5加密
    反射的一些基本用法
    数据的增删改查(三层)<!--待补充-->
    linux文件的硬连接和软连接
    linux磁盘用满的两种情况
  • 原文地址:https://www.cnblogs.com/aha/p/1894114.html
Copyright © 2011-2022 走看看