1. [代码][JavaScript]代码

(function ($) {
    $.fn.placeholder = function (options) {
        var defaults = {
            pColor: "#ccc",
            pActive: "#999",
            pFont: "14px",
            activeBorder: "#080",
            posL: 8,
            zIndex: "99"
        },
        opts = $.extend(defaults, options);
        //
        return this.each(function () {
            if ("placeholder" in document.createElement("input")) return;
            $(this).parent().css("position", "relative");
            var isIE = $.browser.msie,
            version = $.browser.version;
  
            //不支持placeholder的浏览器
            var $this = $(this),
                msg = $this.attr("placeholder"),
                iH = $this.outerHeight(),
                iW = $this.outerWidth(),
                iX = $this.position().left,
                iY = $this.position().top,
                oInput = $("<label>", {
                "class": "test",
                "text": msg,
                "css": {
                    "position": "absolute",
                    "left": iX + "px",
                    "top": iY + "px",
                    "width": iW - opts.posL + "px",
                    "padding-left": opts.posL + "px",
                    "height": iH + "px",
                    "line-height": iH + "px",
                    "color": opts.pColor,
                    "font-size": opts.pFont,
                    "z-index": opts.zIndex,
                    "cursor": "text"
                }
                }).insertBefore($this);
            //初始状态就有内容
            var value = $this.val();
            if (value.length > 0) {
            oInput.hide();
            };
  
            //
            $this.on("focus", function () {
                var value = $(this).val();
                if (value.length > 0) {
                    oInput.hide();
                }
                oInput.css("color", opts.pActive);
                //
  
                if(isIE && version < 9){
                    var myEvent = "propertychange";
                }else{http://www.huiyi8.com/hunsha/lifu/​
                    var myEvent = "input";
                }婚纱礼服欣赏
  
                $(this).on(myEvent, function () {
                    var value = $(this).val();
                    if (value.length == 0) {
                        oInput.show();
                    } else {
                        oInput.hide();
                    }
                });
  
            }).on("blur", function () {
                var value = $(this).val();
                if (value.length == 0) {
                    oInput.css("color", opts.pColor).show();
                }
            });
            //
            oInput.on("click", function () {
                $this.trigger("focus");
                $(this).css("color", opts.pActive)
            });
            //
            $this.filter(":focus").trigger("focus");
        });
    }
})(jQuery)
2. [代码]调用方法:  
//解决IE下不支持placeholder
if($.browser.msie) { 
$(":input[placeholder]").each(function(){
$(this).placeholder();
});
}

最新文章

  1. Plant Design Review Based on AnyCAD
  2. get_magic_quotes_gpc函数
  3. Java Hour 39 Maven ( 1 )
  4. Jquery 表格操作,记录分页情况下,每一页中被用户勾选的信息
  5. 初识HTTP 1.1与HTTP 1.0
  6. Python 网页爬虫 &amp; 文本处理 &amp; 科学计算 &amp; 机器学习 &amp; 数据挖掘兵器谱(转)
  7. Cisco模拟器使用和静态路由配置
  8. 轮子来袭 vJine.Core 之 AppConfig&lt;T&gt;
  9. 关于C++对汉字拼音的处理(2)
  10. cuda(1) 最大并发量
  11. demo_05HTML5+CSS3绘制小鸟
  12. EntityFrameowk6.1 使用enum和低版本的不同
  13. jquery多级下拉菜单
  14. [Luogu3377]【模板】左偏树(可并堆)
  15. java中断
  16. VirtualBox: How to config higher screen resolution
  17. 关于redis分布式锁的实现方式(转载)
  18. PROJ.4学习——地图投影
  19. 关于freemarker 空变量的接收以及类型转换 笔记
  20. 基于mpvue搭建微信小程序

热门文章

  1. json-path解析json方便可靠
  2. /etc/shadow 密码加密方法
  3. Java数组去掉反复的方法集
  4. VMware-Fusion-7.0.0-2103067 Pro SN:序列号+ 百度云下载地址
  5. Spring配置错误记录
  6. linux history 命令 禁用history
  7. 百思不得姐之&amp;quot;我的&amp;quot;模块功能(六)
  8. SPOJ SUBLEX - Lexicographical Substring Search 后缀自动机 / 后缀数组
  9. springcloud微服务实战--笔记
  10. vscode webstrom 配置 eslint 使用 airbnb 规范