分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

实用的placeholder插件,兼容IE下的placeholder,jquery插件

发布时间:2023-09-06 02:14责任编辑:傅花花关键词:暂无标签

placeholder在IE下无法兼容 ,下面的插件很好的处理了这个问题,拿去不谢

 1 /* 2 ?* jQuery placeholder, fix for IE6,7,8,9 3 ?* @website itmyhome.com 4 ?*/ 5 var JPlaceHolder = { 6 ????//检测 7 ????_check : function(){ 8 ????????return ‘placeholder‘ in document.createElement(‘input‘); 9 ????},10 ????//初始化11 ????init : function(){12 ????????if(!this._check()){13 ????????????this.fix();14 ????????}15 ????},16 ????//修复17 ????fix : function(){18 ????????jQuery(‘:input[placeholder]‘).each(function(index, element) {19 20 ????????????var self = $(this), txt = self.attr(‘placeholder‘);21 ????????????self.wrap($(‘<div></div>‘).css({position:‘relative‘, zoom:‘1‘, border:‘none‘, background:‘none‘, padding:‘none‘, margin:‘none‘}));22 ????????????var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css(‘padding-left‘);23 24 ????????????var holder = $(‘<span></span>‘).text(txt).css({position:‘absolute‘, left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:‘#aaa‘}).appendTo(self.parent());25 ????????????self.focusin(function(e) {26 ????????????????holder.hide();27 ????????????}).focusout(function(e) {28 ????????????????if(!self.val()){29 ????????????????????holder.show();30 ????????????????}31 ????????????});32 ????????????holder.click(function(e) {33 ????????????????holder.hide();34 ????????????????self.focus();35 ????????????});36 ????????});37 ????}38 };39 40 //执行41 jQuery(function(){42 ????JPlaceHolder.init(); ???43 });

实用的placeholder插件,兼容IE下的placeholder,jquery插件

原文地址:https://www.cnblogs.com/wm218/p/9617243.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved