jQuery实现ie浏览器兼容placeholder效果
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>jQuery实现IE浏览器兼容placeholder效果</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
} .input {
width: 200px;
height: 30px;
line-height: 30px;
padding: 0 10px;
border: 1px solid #ddd;
margin: 20px auto;
display: block;
}
</style>
</head> <body>
<input type="text" placeholder="请输入姓名" class="input" />
<script src="http://apps.bdimg.com/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { //判断浏览器是否支持placeholder属性
supportPlaceholder = 'placeholder' in document.createElement('input'), placeholder = function(input) { var text = input.attr('placeholder'),
defaultValue = input.defaultValue; if (!defaultValue) { input.val(text).addClass("phcolor");
} input.focus(function() { if (input.val() == text) { $(this).val("");
}
}); input.blur(function() { if (input.val() == "") { $(this).val(text).addClass("phcolor");
}
}); //输入的字符不为灰色
input.keydown(function() { $(this).removeClass("phcolor");
});
}; //当浏览器不支持placeholder属性时,调用placeholder函数
if (!supportPlaceholder) { $('input').each(function() { text = $(this).attr("placeholder"); if ($(this).attr("type") == "text") { placeholder($(this));
}
});
} });
</script>
</body> </html>
效果图:
jQuery实现ie浏览器兼容placeholder效果的更多相关文章
- 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果
placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...
- 跨浏览器实现placeholder效果的jQuery插件
曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...
- jQuery 两种方法实现IE10以下浏览器的placeholder效果
/* ** jQuery版本:jQuery-1.8.3.min.js ** 测试的浏览器:IE8,IETester下的IE6-IE9** Author:博客园小dee */ placeholder是H ...
- ie兼容placeholder效果
转载:http://www.jb51.net/article/56244.htm placeholder是HTML5<input>的属性之一,在不同的浏览器( 支持HTML5的现代浏览器 ...
- Jquery ajaxSubmit()的浏览器兼容问题
form.ajaxSubmit({ 2 beforeSubmit: function() { 3 if (FinanceUtil.validate(form)) { 4 FinanceUtil.loa ...
- 低版本IE内核浏览器兼容placeholder属性解决办法
最简便的一个方法,通过js实现. <input type="text" name="username" id="username" v ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...
- IE下支持文本框和密码框placeholder效果的JQuery插件
基于jQuery实现的,主要用于IE下实现placeholder效果,可同时支持文本和密码输入框.placeholder是HTML5新增的一个属性,当input设置了该属性后,该值的内容将作为灰色提示 ...
随机推荐
- aop编程术语
- 理解python中的元类
一,理解类也是对象 在python中类同样也是一种对象,只要使用关键字class,Python解释器在执行的时候就会创建一个对象,这个对象(类)自身拥有创建对象(类实例)的能力,这就是为什么他是一个类 ...
- Github 使用的Markdown语言
简介 官方站点:http://daringfireball.net/projects/markdown/syntax 中文介绍:http://www.worldhello.net/gotgithub/ ...
- 20-list简单使用:
C++list的使用总结及常用list操作 C++中list用法详解 STL中list的erase()方法的使用 listiterator 最近刚刚接触stl的list 学习的时候遇到了很多 ...
- SqlSugar Asp.Net 高性能ORM框架
SqlSugar从去年到现在已经一年了,版本从1.0升到了现在的2.4.1 ,这是一个稳定版本 ,有数家公司已经项目上线,在这里我将SqlSugar的功能重新整理成一篇新的贴子,希望大家喜欢. 公司团 ...
- Linux 系统配置
centos 7 防火墙和端口配置开启redis端口,修改防火墙配置文件 vi /etc/sysconfig/iptables 加入端口配置 -A RH-Firewall-1-INPUT -m sta ...
- vs2012安装qt5.5.1
https://blog.csdn.net/a6513806/article/details/80098057
- OracleBulkCopy 修正帮
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Refle ...
- nginx在windows平台下的使用笔记
nginx主要提供反向代理及负载均衡的能力,重定向报文代理及报文数据替换也是常用功能.(参考https://www.cnblogs.com/fanzhidongyzby/p/5194895.html) ...
- 关于如何在服务器上搭建tomcat并发布自己的web项目
最近在学习如何在服务起上搭建tomcat,并发布自己的项目,自己是花了一下午的时间才把里面的东西弄明白,各种百度,各种请教大神,真的是备受折磨啊.好了废话不多说,直接进入主题. 1:众所周知,tomc ...