<!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. [转载]Emmet使用手册

    转载地址:  http://www.w3cplus.com/tools/emmet-cheat-sheet.html 介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率 ...

  2. 【py网页】urlopen的补充,完美

    urllib 是 python 自带的一个抓取网页信息一个接口,他最主要的方法是 urlopen(),是基于 python 的 open() 方法的.下面是主要说明: 1 urllib.urlopen ...

  3. Openstack的用户登录流程

    openstack的用户登录,需要获得集中权限. token 只需要提供用户名和密码即可获得,接口 http://public_url/tokens method:POST body:{"a ...

  4. sql server 2008 安装过程与创建建sql server登录用户

    1.sql server 下载安装包路径:http://pan.baidu.com/s/1qWuzddq 2.安装过程图解教程 ,参照网址:http://jingyan.baidu.com/album ...

  5. HTML data属性简介以及低版本浏览器兼容算法

    实例 使用 data-* 属性来嵌入自定义数据: <ul> <li data-animal-type="bird">Owl</li> <l ...

  6. STM32模拟I2C

    之前为了测试, 拿最小板做了一个I2C的主发跟主读, 一开始当然是尝试用硬件I2C, 结果弄了很久, 时间紧迫, 只好用了模拟, 结果发现, 哎, 真特么挺好用的, 现在1片儿顶过去5片儿. 硬件I2 ...

  7. 启动管理软件服务器时,提示midas.dll错误

    首先确认系统以及管理软件目录内是否有midas.dll文件,如果没有,请复制或下载midas.dll到相应目录.系统默认路径为:'c:\windows\system32\' 然后依次打开“开始菜单”内 ...

  8. java网络编程之TCP通讯

    java中的网络编程之TCP协议的详细介绍,以及如何使用,同时我在下面举2例说明如何搭配IO流进行操作, /* *TCP *建立连接,形成传输数据的通道: *在连接中进行大数据量传输: *通过三次握手 ...

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

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

  10. Swoole + zphp 改造为专门用来开发接口的框架

    The other problem I had with Laravel Task Scheduling was that i really only wanted something to hand ...