模拟placeholder支持ie8以下处理了密码框只读的问题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form id="form1" action="">
<input type="text" name="username" placeholder="请输入用户名">
<input type="password" name="password" placeholder="请输入密码">
<input type="password" name="password2" placeholder="请确认密码">
<input type="text" name="email" placeholder="请输入邮箱">
</form> <script type="text/javascript">
(function(){
//检测是否支持placeholder
if('placeholder' in document.createElement('input')) return; var form = document.getElementById('form1'),
inputs = form.getElementsByTagName('input'),
i,input,value,type; //获取焦点事件
var focus = function(value,type){
return function(){
if(this.value === value) this.value = '';
if(this.value === '' && type === 'password'){
try {
this.type = 'password';
}catch(e){
this.style.visibility = 'hidden';
this.style.position = 'absolute';
this.nextSibling.style.visibility = 'visible';
this.nextSibling.style.position = 'relative';
//定位光标
this.nextSibling.focus();
}
}
};
}; //失去焦点事件
var blur = function(value,type){
return function(){
if(this.value === '') this.value = value;
if(this.value === value && type === 'password'){
try{
this.type = 'text';
}catch(e){
this.style.visibility = 'hidden';
this.style.position = 'absolute';
this.previousSibling.style.visibility = 'visible';
this.previousSibling.style.position = 'relative';
}
}
};
}; //如果浏览器是ie8以下,则创建一个文本框与密码框切换显示
var createInput = function(value,type,type2){
var tmp = document.createElement('input');
tmp.type = type;
tmp.name = this.name;
tmp.placeholder = value;
tmp.value = value;
tmp.onfocus = focus(value,type2);
tmp.onblur = blur(value,type2);
form.insertBefore(tmp,this);
this.style.visibility = 'hidden';
this.style.position = 'absolute';
} for(i=0;i<inputs.length;i++){
input = inputs[i]; //不是文本框跳过
if(input.type !== 'text' && input.type !== 'password') continue; type = 'text';
value = input.getAttribute('placeholder'); if(input.type === 'password'){ type = 'password'; //给密码框做一个标记 //ie8以下input type是只读的
try {
input.type = 'text';
}catch(e){
createInput.call(input,value,'text',type);
i++;
}
} input.value = value;
input.onfocus = focus(value,type);
input.onblur = blur(value,type);
}
})();
</script>
</body>
</html>
模拟placeholder支持ie8以下处理了密码框只读的问题的更多相关文章
- 在IE8等不支持placeholder属性的浏览器中模拟placeholder效果
placeholder是一个很有用的属性,可以提示用户在input框中输入正确的内容,但是IE8以及IE8一下的浏览器不支持该属性,我们可以使用js来模拟相似的效果.下面直接上代码: <!doc ...
- IE下支持文本框和密码框placeholder效果的JQuery插件
基于jQuery实现的,主要用于IE下实现placeholder效果,可同时支持文本和密码输入框.placeholder是HTML5新增的一个属性,当input设置了该属性后,该值的内容将作为灰色提示 ...
- jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...
- 关于input标签和placeholder在IE8,9下的兼容问题
一. input常用在表单的输入,包括text,password,H5后又新增了许多type属性值,如url, email, member等等,考虑到非现代浏览器的兼容性问题,这些新的type常用在移 ...
- jquery异步上传文件,支持IE8
http://code.taobao.org/p/upload2/src/ 已经托管至淘宝code 源码:http://code.taobao.org/p/upload2/src/jquery.upl ...
- placeholder兼容IE8解决方案
1.原因:placeholder是h5的新属性,IE10以前的浏览器(8.9)不支持此属性. 2.解决方法:jQuery三方插件 jquery-placeholder 3.快速开始: <! ...
- bootstarp3 支持ie8
http://blog.csdn.net/hyb3280660/article/details/51850832 想要bootstarp3 支持ie8? 引入 <!-- 存放全局css/js - ...
- 获取表单的初始值,模拟placeholder属性
input和textarea有一个默认属性defaultValue,即初始值. 即使在页面操作修改了input和textarea的内容,获取到的defaultValue依然是初始值.可通过该值模拟pl ...
- Bootstrap 3 支持 IE8
Bootstrap 3 支持 IE8 <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries ...
随机推荐
- 最全面的NSDateHelper 分享
NSDateUtil 分享 (ios开发交流群:486468672) 代码下载:https://github.com/foxswang/NSDateUtil 史上最全面NSDate Utility 没 ...
- Swift设置自动行高
// 设置行高自适应 tableView.rowHeight = UITableViewAutomaticDimension // 设置预估行高 tableView.estimatedRowHeigh ...
- Android Studio Gradle Build Running 特别慢的问题探讨
本文的本本win7 64bit 6G android studio2.1 在运行程序的时候Gradle Build Running 特别慢,一个helloworld都快2min了 1.开启gradle ...
- 【iOS】小项目框架设计(ReactiveCocoa+MVVM+AFNetworking+FMDB)
上一个项目使用到了ReactiveCocoa+MVVM+AFNetworking+FMDB框架设计,从最初的尝试,到后来不断思考和学习,现在对这样一个整体设计还是有了一定了理解与心得.在此与大家分享下 ...
- UILabel和NSAttributedString那些事
注:通常的label用来现实普通的文字.但是,你常常会遇到这样的情况:一段文字中不仅有文字,也有图片,甚至文字中的某段文字与其他的文字的appearance不一致的情况,这样的一段文字就可以称得上是富 ...
- net2.0对于递归变量的处理方式不同引发的递归问题
同样的代码,用NET2.0执行产生的效果与其它框架使用的不同,导致报错. 认真查找原因后发现该程序的编写人员隐式的使用了一个公共变量,使之在递归过程中不断的被改写,使得1次递归后就破坏了原来的循环体, ...
- 聚合及UML表示
聚合聚合是一种特别类型的关联,用于描述“总体到局部”的关系. 聚合分成: 基本聚合与合成聚合 基本聚合: 基本聚合一般也简称为聚合(Aggregation).在基本的聚合关系中, 部分类(B) ...
- mysql禁用autocommit,以及遇到的问题
原文地址:http://blog.51yip.com/mysql/1230.html http://blog.csdn.net/ying_593254979/article/details/12095 ...
- python可分组字典
# -*- encoding: UTF-8 -*- from collections import defaultdict class News(object): def __init__(self, ...
- TCMalloc 安装和使用
前面三篇译文<TCMalloc:线程缓冲的Malloc>.<使用TCMalloc的堆栈检查>.<使用TCMalloc进行堆栈分析>介绍了TCMalloc的基本原理, ...