<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>placeholder</title>
<style type="text/css">
.label{position: relative; display: inline-block; *zoom:1; *display: inline;
*vertical-align: middle;}
.label label{ position: absolute; left:0px; top:0; font-size: 12px;cursor: text; text-indent: 5px;}
.label input{ padding: 9px 5px; height: 14px; line-height: normal; border: 1px solid #ccc; font-size: 14px;}
</style>
</head>
<body>
请输入用户名:
<div class="label">
<label for="user">请输入用户名</label>
<input type="text" id="user" />
</div>
</body>
</html>
<script type="text/javascript">
var aLabel=document.getElementsByTagName("label")[0];
var aInput=document.getElementsByTagName("input")[0];
aLabel.style.lineHeight=aLabel.style.height=aInput.offsetHeight+"px";
if (aInput.value.length!=0){
aLabel.style.display="none"
}else{
aLabel.style.display="block"
};
aInput.onfocus=function(){
aLabel.style.display="none";
}
aInput.onblur=function(){
if (aInput.value.length!=0){
aLabel.style.display="none"
}else{
aLabel.style.display="block";
}; } </script>

方法二

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>placeholder</title>
</head>
<body>
<input type="text" placeholder="请输入用户名" />
</body>
</html>
<script>
function placeholder(opts){
if("placeholder" in document.createElement('input')){
return;
}else{
this.obj=opts.obj;
this.init();
this.focus();
this.blur();
}
}
placeholder.prototype.init= function(){
if (this.obj.getAttribute("placeholder") && this.obj.value.length==0){
this.obj.value=this.obj.getAttribute("placeholder");
}
};
placeholder.prototype.focus=function(){
var _this=this;
this.obj.onfocus=function(){
if (_this.obj.value==_this.obj.getAttribute("placeholder")){
_this.obj.value="";
};
}
};
placeholder.prototype.blur=function(){
var _this=this;
this.obj.onblur=function(){
if (_this.obj.value.length==0){
_this.obj.value=_this.obj.getAttribute("placeholder");
};
}
};
var aInput=document.getElementsByTagName("input")[0];
new placeholder({"obj":aInput});
</script>

方法三,

背景图片,限制太多,代码就不贴上来了

placeholder的兼容性探索之路的更多相关文章

  1. 对于placeholder浏览器兼容性(包括密码输入框)解决办法

    将以下脚本和样式引入你的页面(对于密码输入框,要设置ID属性值): <script type="text/javascript"> $(function () { // ...

  2. 解决HTML5中placeholder属性兼容性的JQuery插件

    //调用方法 $(function () {   $(".pHolder").jason(); }); //HTML代码 <input type="text&quo ...

  3. placeholder不兼容 IE10 以下版本的解决方法

    对于密码输入框placeholder的兼容问题:HTML代码:<input type="password" id="loginPassword" plac ...

  4. 让Placeholder在IE中燥起来

    网上有好多关于这方面解决兼容性问题的文章,很多招式,学会这一招,让你轻松搞定Placeholder的兼容性,叫我好人,拿走,不谢.... placeholder属性是HTML5 中为input添加的. ...

  5. 跨浏览器实现placeholder效果的jQuery插件

    曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...

  6. html5 placeholder属性兼容ie11

    placeholder 属性是html5的属性,用于提供描述输入字段预期值的提示信息(hint). 简单例子: <!DOCTYPE HTML> <html> <body& ...

  7. HTML 使用CSS 如何去掉文本聚焦框 HTML 使用CSS 如何去掉文本聚焦框 : outline 值设为none 修改input、textarea输入框placeholder样式

    HTML 使用CSS 如何去掉文本聚焦框 : outline 值设为none 修改input.textarea输入框placeholder样式  兼容性代码: input::-webkit-input ...

  8. placeholder IE兼容,显示password

    从网上找了很多关于placeholder IE兼容性的问题,下边的这个js方法可以显示password. <!doctype html> <html lang="en&qu ...

  9. 我写的一些前端开源项目(均托管到github)

    大部分项目都是平时项目用到的某些功能,觉得有趣或者复用性有点高就提取成一个单独项目来做维护 coffee-tmpl : 一个极简的模板引擎和ejs及underscore的template类似 turn ...

随机推荐

  1. Workflow Mailer Notifications设置

    参考:http://www.docin.com/p-651716490.html http://www.360doc.com/content/12/0218/15/3200886_187602886. ...

  2. bootstrap, boosting, bagging 几种方法的联系

    http://blog.csdn.net/jlei_apple/article/details/8168856 这两天在看关于boosting算法时,看到一篇不错的文章讲bootstrap, jack ...

  3. PAT乙级 1027. 打印沙漏(20)

    1027. 打印沙漏(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求你写个程序把给定的符号打印成 ...

  4. webpack我遇到的一些坑

    我的第一个用于实验webpack的项目是一个拥有多个版本的项目.什么叫多个版本?这个项目对3个语言版本+3个不同城市版本+(移动端  + PC端),也就是3*3*2,18个版本. 我的第一次想法肯定是 ...

  5. SQL SERVER 2008 R2配置管理器出现“远程过程调用失败”【0x800706be】的解决办法

    以前SQL Server 2008 不能登陆的时候,总是通过“计算机管理”→“SQL Server服务”更改一下,"SQL Server(MSSQLSERVER)".可是现在出现的 ...

  6. 《REWORK》启示录 发出你的心声——程序员与身体

    Sound Like You 所谓的标题在这里并不是为了吸引眼球,不过也是为了吸引眼球,只是出发点已经不一样了.这是一篇适合给程序员看的关于健康的文章,也许你认识李开复也可以给他看看,上过养生过,觉得 ...

  7. android 项目学习随笔十九(MD5)

    import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...

  8. 表数据文件DBF的读取和写入操作

    import sys import csv import struct import datetime import decimal import itertools from cStringIO i ...

  9. 6.1:SportStore:一个真实的应用

    之前的小例子让我们演示了AngularJS的一些特性,但他们缺少上下文.要解决这个问题,作者要创建一个简单单真实的电子商务应用. 作者将创建一个在线产品分类,客户可以通过分类和页面浏览,一个购物车用户 ...

  10. 给NIOS II CPU添加一颗澎湃的心——sysclk的使用

    给NIOS II CPU添加一颗澎湃的心——系统时钟的使用 本实验介绍如何在Qsys中添加一个定时器作为NIOS II的心跳定时器,并在NIOS II中软件编程使用该定时器. 将上一个实验watchd ...