input 的 placeholder属性在IE8下的兼容处理
placeholder是input标签的新属性,在使用的时候有两个问题:
1、IE8 下不兼容
处理思路:
如果浏览器不识别placeholder属性,给input添加类名placeholder,模仿placeholder属性的样式,并给input 的value赋值placeholder属性的值
2、 input的type属性是password的情况,用上面的方法处理提示语为密码文
处理思路:
新添加一个标签,模仿placeholder属性
直接上代码:
css部分:
.input-item {
position: relative;
margin: 10px;
}
.pwd-place {
position: absolute;
top:;
left: 72px;
width: 100%;
height: 100%;
font-size: 12px;
}
html部分:
<form action="#">
<div class="input-item">
<label for="userName">用户名:</label>
<input class="username" id="userName" type="text" placeholder="请输入用户名">
</div>
<div class="input-item">
<label for="pwd">密码:</label>
<input class=" password" id="pwd" type="password" placeholder="请输入密码">
<span class="pwd-place"></span>
</div> </form>
js部分:
<script src="jquery-1.11.3.js"></script>
<script>
function placeholder(el){ function isPlaceholer(){
var input = document.createElement("input");
return "placeholder" in input;
} var $el = $(el);
if( isPlaceholer()==false && !('placeholder' in document.createElement('input')) ){ $('input[placeholder],textarea[placeholder]').each(function(){
var that = $(this),
text= that.attr('placeholder');
if(that.val()===""){
if(that.attr("type") == "password"){
$el.html("请输入密码");
}else {
that.val(text).addClass('placeholder');
}
}
that.focus(function(){
if($el.html() == text){
$el.html("");
}
if(that.val()===text) {
that.val("").removeClass('placeholder'); }
})
.blur(function(){
if(that.val()==="") {
if (that.attr("type") == "password") {
$el.html("请输入密码"); }else {
that.val(text).addClass('placeholder');
}
}
})
.closest('form').submit(function(){
if(that.val() === text){
that.val('');
}
});
});
}
}
$(document).ready(function() {
placeholder(".pwd-place")
});
</script>
input 的 placeholder属性在IE8下的兼容处理的更多相关文章
- input输入框的border-radius属性在IE8下的完美兼容
在工作中我们发现搜索框大部分都是有圆角的,为此作为经验不足的前端人员很容易就想到,给input标签添加border-radius属性不就解决了嘛.不错方法确实是这样,但是不要忘了border-radi ...
- Hmtl5 <input>中placeholder属性(新属性)
Hmtl5 <input>中placeholder属性(新属性) 一.定义和用法 placeholder 属性提供可描述输入字段预期值的提示信息(hint). 该提示会在输入字段为空时显示 ...
- 解决input标签placeholder属性浏览器兼容性问题的一种方法
为文本框input添加文字输入提示,H5为input提供了一个placeholder属性.在支持H5的浏览器中,用此属性设置输入提示,简单方便,但是对于IE8以下版本,都不支持placeholder属 ...
- 修改 input / textarea placeholder 属性的颜色和字体大小
话不多说,直接上代码: input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { color: #666; fon ...
- 前端 html input标签 placeholder属性 标签上显示内容
前端 html input标签 的placeholder属性 标签上显示内容 <!DOCTYPE html> <html lang="en"> < ...
- IE8下的兼容小经验
placeholder IE8下不支持HTML5属性placeholder,不过为解决此问题的js插件挺多的,比如:jquery-placeholder.也可以使用jquery来写. last-chi ...
- bootstrap在ie8下,兼容媒体查询
最近使用bootstrap做网站的时候发现,在ie8下的媒体查询一直失效: 后来解决了,做如下记录: 1.必须运行在服务器下 2.hack 条件语法,如下: <!--[if lte ie 9]& ...
- ie8不兼容input的placeholder属性但是要实现其效果的方法
通过学习前辈的思想,个人想法整理如下: 通过两个元素标签,仿造出placeholder的内容 使用position定位好两个元素标签 第一要隐藏两个元素标签display:none,在<!--[ ...
- angular自定义指令解决IE89不支持input的placeholder属性
下面代码实测通过,直接copy到本地运行即可. <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
随机推荐
- linux移植简介[MS2]
一:修改Makefile 1添加编译选项,2添加时钟 二:图形化配置(make menuconfig) 此时生成zlmage, 可以跑起来 三:对NandFlash配置,yaffs2 文件系统配置, ...
- 【PythonChallenge】Level 3
题目为正则表达式,需要注意EXACTLY的含义,即AAAAxBBB中x不满足条件,但aAAAxBBBa却满足条件.使用perl解决此题,利用s///替换字母,循环读取整个源码文件,结果为linkedl ...
- Android开发UI之Fragment-Tabbed Activity的使用
使用ADT新建的时候,可以选择Tabbed Activity,选择新建一个工程. 新建的工程中,选择不同的Tab页显示不同的内容,主要是通过SectionsPagerAdapter类中的Fragmen ...
- ccleaner的专业版和商业版的注册码
名称:Registered User 密钥:CBB4-FJN4-EPC6-G5P6-QT4C 断网注册
- POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)
描述 http://poj.org/problem?id=3258 给出起点和终点之间的距离L,中间有n个石子,给出第i个石子与起点之间的距离d[i],现在要去掉m个石子(不包括起终点),求距离最近的 ...
- AHOI2009最小割
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1072 Solved: 446[Submit] ...
- apache开源项目--Lens
Lens 提供了一个统一数据分析接口.通过提供一个跨多个数据存储的单一视图来实现数据分析任务切分,同时优化了执行的环境.无缝的集成 Hadoop 实现类似传统数据仓库的功能. 该项目主要特性: 简单元 ...
- 结合Zen Coding快速编写HTML代码(sublime text2篇)
首先说下,如何在sublime text2加上zen coding插件 按 Ctrl+`(就是~这个键) 复制下面的代码 确认 重新启动sublime text2 import urllib2,os; ...
- STSdb
打开数据库并写入数据 ? using (StorageEngine engine = new StorageEngine("stsdb4.sys", "stsdb4.da ...
- Html笔记(四)图像
图像标签: <img> <img src="../dir/file" alt="说明文字" height width border/> ...