<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>placeholder 效果的实现</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<style>
body {
        font-size: 12px;
} div {
        position: relative;
} .userName-group,
.pswd-group{
        width: 153px;
        height: 24px;
        margin-bottom:10px;
} label{
        margin-left:3px;
        line-height: 24px;
        z-index: 1;
        color: #999;
}
.userName-group input,
.pswd-group input{
        position: absolute;
        top: 0;
        left:0;
        width: 153px;
        height:22px;
        border:1px solid #bbb;
        z-index: 999;
        background-color: transparent;
}
</style>
<body>
<h1>placeholder 效果</h1>
<input type="text" placeholder="用户名">
<input type="password" placeholder="密码"> <h1>placeholder 效果的实现</h1> <div class="userName-group">
    <label for="username">用户名</label>
    <input type="text" id="username">
</div>
<div class="pswd-group">
    <label for="password">密码</label>
    <input type="password" id="password">
</div>
<script> /*$(function(){        
        var input=$("input"),
                len=input.length;
        for(var i=0;i<len;i++){//判断浏览器是否记住信息
                var val=input.eq(i).val();
                if(val!==''){
                        input.eq(i).prev('label').hide();
                }
        }
        $("label").click(function(){
                $(this).next().focus();
        })        
        $("#username,#password").keydown(function(){
                $(this).prev().hide();
        }).blur(function(){
                var _this=$(this);
                if (_this.val() == ''){
                        _this.prev().show();
                }
        });
})*/ //判断浏览器
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject){
        Sys.ie = ua.match(/msie ([\d.]+)/)[1];
}
//else if (document.getBoxObjectFor){
//        Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1];
//}else if (window.MessageEvent && !document.getBoxObjectFor){
//        Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1];
//}else if (window.opera){
//        Sys.opera = ua.match(/opera.([\d.]+)/)[1];
//}else if (window.openDatabase){
//        Sys.safari = ua.match(/version\/([\d.]+)/)[1];
//} window.onload=function(){        
        var        input=document.getElementsByTagName('input'),
                label=document.getElementsByTagName('label'),
                username=document.getElementById('username'),
                pwd=document.getElementById('password'),
                len=input.length;
                
        for(var i=0;i<len;i++){
                var val=input.item(i).value,
                        div=input.item(i).parentNode;
                if(val!==''){
                        label_s_h(div,'none');
                }
        }
        label.onclick=function(){
                this.nextSibling('input').focus;        
        }         username.onkeydown=pwd.onkeydown=function(){
                var div=this.parentNode;
                        label_s_h(div,'none');
        }
        username.onblur=pwd.onblur=function(){
                var _this=this,
                        div=this.parentNode,
                        val=_this.value;
                if(val==''){
                        label_s_h(div,'block');
                }
        }
}
s=Sys.ie||'';//没有空s为undefined
function label_s_h(o,d){
        /*if(s=='6.0'||s=='7.0'||s=='8.0'){
                //s.indexOf('6'||'7'||'8')>0不知道为什么这样不对 ??
                //s=='6.0'||'7.0'||'8.0' 写在label_s_h()函数里判断就出错,chrome下也执行到这里,不写在函数里是对的
                o.firstChild.style.display=d;//不知道为什么不能用.previousSibling ??
                
        }else{
                o.childNodes[1].style.display=d;//不知道为什么ie9以上和chrome不支持firstChild ???
        }*/
        s=='6.0'||s=='7.0'||s=='8.0'?o.firstChild.style.display=d:o.childNodes[1].style.display=d;
} </script>
</body>
</html>

placeholder 效果的实现,input提示字,获取焦点时消失的更多相关文章

  1. input提示字在有焦点消失或输入改变时消失

    一:获取焦点时 提示字消失 <input type="text" name="textfield" value="这里是提示内容" o ...

  2. IOS 固定定位底部input输入框,获取焦点时弹出的输入法键盘挡住input

    移动页面经常会做到这样一个效果,看下面的图片,重点就是那个固定定位的底部,里面有个input输入框,在输入字符的时候,安卓手机看着是完全没有问题! 1.页面没有点击底部input的初始状态 2.安卓手 ...

  3. a、button、input点击获取焦点时出现蓝色边框,如何去掉

    a,button,input{ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-modify: read-write-plain ...

  4. HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置

    在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...

  5. HTML 5 <input> placeholder 属性 实现搜索框提示文字点击输入后消失

    H5之前要实现这个功能还要用到JS,H5出来之后新增加了placeholder属性,有了这个属性就就能轻松实现这个功能. 定义和用法 placeholder 属性提供可描述输入字段预期值的提示信息(h ...

  6. 浅谈实现placeholder效果的几种方案

    placeholder是html5<input>的一个属性,它提供可描述输入字段预期值的提示信息(hint), 该提示会在输入字段为空时显示.高端浏览器支持此属性(ie10/11在获得焦点 ...

  7. 编辑框添加灰色提示字(html+VC)

    Html中添加灰色提示字,使用属性placeholder即可! <input type="text" placeholder="要显示的文字"> 但 ...

  8. 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果

    placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...

  9. 在IE8等不支持placeholder属性的浏览器中模拟placeholder效果

    placeholder是一个很有用的属性,可以提示用户在input框中输入正确的内容,但是IE8以及IE8一下的浏览器不支持该属性,我们可以使用js来模拟相似的效果.下面直接上代码: <!doc ...

随机推荐

  1. HTML5微信长按图片不会弹出菜单的解决方法

    HTML5微信长按图片不会弹出菜单的解决方法 <pre><div ontouchstart = "return false;"></div>&l ...

  2. Android.mk基础

    1.前言 Android.mk用于向编译系统描述源文件和共享库,它实际上是编译系统解析一次或多次的微小GNU makefile片段.它的语法支持将源文件分组为模块,模块是静态库.共享库或独立的可执行文 ...

  3. MySQL常见的应用异常记录

    >>Error Code: 1045. Access denied for user 'test'@'%' (using password: YES) 使用MySQL的select * i ...

  4. SQL Server 10分钟理解游标

    概述 游标是邪恶的! 在关系数据库中,我们对于查询的思考是面向集合的.而游标打破了这一规则,游标使得我们思考方式变为逐行进行.对于类C的开发人员来着,这样的思考方式会更加舒服. 正常面向集合的思维方式 ...

  5. [转帖]统一操作系统 UOS 龙芯版上线

    统一操作系统 UOS 龙芯版上线 看评论很有必要 搞一波 深度的操作系统了https://www.oschina.net/news/112065/chinauos-with-loongson?p=4 ...

  6. 【题解】Luogu P4284 [SHOI2014]概率充电器

    原题传送门 我们知道,每个电器充电对充电电器数的贡献都是相等的1,所以若第\(i\)个电器有\(p_i\)的概率充电时 \[E=\sum_{i=1}^np_i\] 我们考虑如何求\(p_i\),根据树 ...

  7. N-gram理解

    如何来理解这个概率呢? p( i love you) 如果是 =p(i)p(love)p(you) 就是只考虑单词出现的概率本身. 如果是  =p(i)p(love|i)p(you|love)  就是 ...

  8. Java自学-数字与字符串 数学方法

    Java Math类常用方法 java.lang.Math提供了一些常用的数学运算方法,并且都是以静态方法的形式存在 步骤 1 : 四舍五入, 随机数,开方,次方,π,自然常数 package dig ...

  9. django配置文件

    1.BASSE_DIR BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 当前工程的根目录,Django会依 ...

  10. 阿里熔断限流Sentinel研究

    1. 阿里熔断限流Sentinel研究 1.1. 功能特点 丰富的应用场景:例如秒杀(即突发流量控制在系统容量可以承受的范围).消息削峰填谷.集群流量控制.实时熔断下游不可用应用等 完备的实时监控:S ...