IE10-浏览器实现placeholder效果
如下图,在文本框为空时显示提示文字

在IE10+和chrome浏览器加placeholder属性及可实现 ,单在IE10-浏览器并不支持该属性,
以下是placeholder在IE10-浏览器的实现
<style type="text/css">
/*输入框为空时提示文字的样式*/
label.placeholder
{
color: gray;
padding-left: 3px;
cursor: text;
z-index: 1000;
position: absolute;
background: transparent;
font-size: 0.8em;
padding-top: 4px;
}
</style>
<script type="text/javascript">
/* 设置输入框为空时输入框内显示/隐藏提示文字
* @param show 是否显示提示文字,默认显示
*/
$.fn.setHint = function (show) {
if ('placeholder' in document.createElement('input'))
return; var word = this.attr("placeholder");
if (word) {
show = (show == undefined) ? (this.val() == "") : show; //根据内容是否为空确定是否显示
if (show && this.val() == "") {
this.prev("label.placeholder").show();
} else if (!show) {
this.prev("label.placeholder").hide();
}
}
}; // 页面初始化执行的脚本
$(function () {
// IE10及以上浏览器支持placeholder属性,不需要用脚本实现
if (!('placeholder' in document.createElement('input'))) {
$(":text[placeholder],:password[placeholder],textarea[placeholder]").wrap("<span></span>")
.focus(function () {
$(this).prev("label.placeholder").hide();
}).blur(function () {
if ($(this).val() == "") {
$(this).prev("label.placeholder").show();
}
}).each(function () {
var labelHtml = "<label class='placeholder'>" + $(this).attr("placeholder") + "</label>";
$(labelHtml).insertBefore(this).click(function () {
$(this).hide().next().focus();
}).toggle($(this).val() == "");
});
}
});
</script>
html:
<input type="text" placeholder="请输入用户名" />
IE10-浏览器实现placeholder效果的更多相关文章
- 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果
placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...
- jQuery实现ie浏览器兼容placeholder效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 跨浏览器实现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【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...
- 浅谈实现placeholder效果的几种方案
placeholder是html5<input>的一个属性,它提供可描述输入字段预期值的提示信息(hint), 该提示会在输入字段为空时显示.高端浏览器支持此属性(ie10/11在获得焦点 ...
- 跨浏览器的placeholder – 原生JS版
转自来源 : http://www.ifrans.cn/placehoder/ 跨浏览器的placeholder – 原生JS版 html5为input元素新增了一个属性”placeholder”,提 ...
- placeholder 效果的实现,input提示字,获取焦点时消失
<!doctype html><html><head><meta charset="utf-8"><title>plac ...
随机推荐
- Junit4
package test.code; import static org.junit.Assert.*; import org.junit.Test; import code.MyCode; publ ...
- 009 The Interfaces In JAVA(官网文档翻译)
Interfaces There are a number of situations in software engineering when it is important for dispara ...
- centos 6.5 samba简单配置
1.安装samba yum -y install samba (我的显示已经安装啦!) 2.编辑samba的配置文件 vi /etc/samba/smb.conf 用 testparm查看我配置后的 ...
- 用命令实现Win7远程桌面关机和重启
关机 shutdown -s -t 0 重启 shutdown -r -t 0 打开运行框(Win+R键),输入上述命令即可,后面的数字表示关机/重启延迟的时间 at 12:00 shutdown - ...
- python中set和frozenset方法和区别
set(可变集合)与frozenset(不可变集合)的区别:set无序排序且不重复,是可变的,有add(),remove()等方法.既然是可变的,所以它不存在哈希值.基本功能包括关系测试和消除重复元素 ...
- javascript代码复用模式
代码复用有一个著名的原则,是GoF提出的:优先使用对象组合,而不是类继承.在javascript中,并没有类的概念,所以代码的复用,也并不局限于类式继承.javascript中创建对象的方法很多,有构 ...
- CSS常用布局整理
固定宽度布局 1-2-1布局(浮动) <html xmlns="http://www.w3.org/1999/xhtml"> <head> <titl ...
- 图解Windows Server 2012 桌面图标
显示桌面图标.壁纸等 1 WIN键+R键,输入: rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0 选择你需要的图标显示到桌面去,如下图所示 ...
- sql case when 多条件
when 'ChangeProductName'= case --联名借姓名 --when a.ChangeProductName is not null then (substr ...
- HBase优化
1.hbase的balance策略是region数量策略,即维持每个regionserver的region数量基本一致,这并未考虑一个table的region可能都落到一个refionserver的不 ...