模拟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 ...
随机推荐
- JavaScriptSerializer序列化时间处理
JavaScriptSerializer序列化时间后会把时间序列化成N进制的鬼数据,于是查了下质料坐下记录 假设list = News List<Text>(){new Text(){id ...
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/39057201),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
一:问题描述: 应用中的Dex 文件方法数超过了最大值65536的上限,简单来说,应用爆棚了. 二.解决方案: 方案1:使用插件化框架 比如: https://github.com ...
- iOS关于CoreAnimation动画知识总结
一:UIKit动画 在介绍CoreAnimation动画前先简单介绍一下UIKit动画,大部分简单的动画都可以使用UIKit动画实现,如果想实现更复杂的效果,则需要使用Core Animation了: ...
- 如何使用SSL pinning来使你的iOS APP更加安全
SSL pinning在构建一个高度安全的移动APP上扮演了一个十分重要的角色.然而如今好多用户在使用无线移动设备去访问无数不安全的无线网络. 这篇文章主要覆盖了SSL pinning 技术,来帮助我 ...
- 【代码笔记】iOS-使图片两边不拉伸,中间拉伸
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...
- socket编程中客户端常用函数 以及简单实现
1 常用函数 1.1 connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...
- 转换Excel表格到MarkDown:exceltk
源码和下载: 源码:https://github.com/fanfeilong/exceltk 下载:http://files.cnblogs.com/files/math/exceltk0.0.9. ...
- drop和delete的区别是什么
当你不再需要该表时, 用 drop;当你仍要保留该表,但要删除所有记录时, 用 truncate;当你要删除部分记录时(always with a WHERE clause), 用 delete.
- Sql server之sql注入篇
SQL Injection 关于sql注入的危害在这里就不多做介绍了,相信大家也知道其中的厉害关系.这里有一些sql注入的事件大家感兴趣可以看一下 防范sql注入的方法无非有以下几种: 1.使用类型安 ...