<!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 audio标签切换播放音乐的方法

    html5 audio标签切换播放音乐的方法<pre><audio id="music1" preload loop="loop">&l ...

  2. python入门之模块

    序什么是包包的作用一.什么是模块二.模块的三种来源三.模块的四种表现形式四.为什么要使用模块五. 如何创建,编写模块,并使用模块5.1 给模块起别名5.2 模块的导入方式5.3 循环导入问题 TOC ...

  3. .net中加密与解密

    .Net中的加密解密 引言 在一些比较重要的应用场景中,通过网络传递数据需要进行加密以保证安全.本文将简单地介绍了加密解密的一些概念,以及相关的数字签名.证书,最后介绍了如何在.NET中对数据进行对称 ...

  4. 25个led灯新玩法

    Microbit板子的25个led灯,是5X5的阵列,led(lights emitting diodes)中文叫发光二极管,有单向导电性,还发光,有各种颜色的,红,蓝,黄等等.mPython可以让你 ...

  5. beego:限制接口访问频率

    package utils import ( "github.com/astaxie/beego" "github.com/astaxie/beego/context&q ...

  6. Reliable Multicast Programming(PGM)协议

    Reliable Multicast Programming (PGM)实际通用可靠多播协议,在某种程度上保证多播的可靠性.是IP上层协议,和TCP还有UDP同级,工作在传输层. 在组播传输视频项目中 ...

  7. C#多线程的同步与通信

    C#中使用lock和Monitor控制多线程对资源的使用,最常见的生产者和消费者问题就是多线程同步和通信的经典例子.了解C#多线程的同步与通信. 一.关于lock和Monitor lock可以把一段代 ...

  8. 关于注解sql和动态sql的写法

    注解写sql一般写在mapper层,如果sql语句复杂建议不要写注解sql 拼接容易出错 二动态sql的话要在 main 下面创建一个resource ——mapper—— Mapper.xml 再在 ...

  9. Smack 4.3.4 API

      Smack 4.3.4 API 包 包 描述 org.igniterealtime.smack.smackrepl Smack的REPL(读取评估打印循环). org.jivesoftware.s ...

  10. chrome安装插件

    看了很多的解决办法,也试了很多种,有的有点用,有的只能用一次,最后成功了,在这里总结一下 一.首先下载 很多人下载的都ctx格式的,然后拖进去安装,用了一次就崩溃了,主要还是安装方式不对,一般需要将下 ...