<!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. HTTP漫谈

    一.说明 1.1 当前背景说明 很多web的书包括web安全的书都会有一章介绍http协议,我就总恶意揣测作者是在凑字数,一般都直接跳过去. 相比TCP/IP这种各字段基于数值代号的协议,http这种 ...

  2. sqlserver替换一个单引号为多个单引号

    SqlServer Where语句中如果有单引号,需要替换为两个单引号,不然会语法错误,替换方法如下REPLACE(@UserName,'''','''''') REPLACE(@UserName,' ...

  3. Svn CleanUp failed解决方案

    在项目目录下找到wc.db文件,使用sqlite工具打开,清空main下的WC_LOCK和 WORK_QUEUE表即可.

  4. 洛谷P5017:摆渡车——题解

    https://www.luogu.org/problem/P5017 参考:https://www.luogu.org/blog/ztyluogucpp/solution-p5017 我想我大概是废 ...

  5. idea Autowired 提示红色的解决方式

  6. K-Means 聚类分析学习笔记

    在之前分享的链家二手房数据分析的练习中用到了 K-Means 聚类分析方法,所以就顺道一起复习一下 K-Means 的基础知识好了. K-Means 聚类分析可将样本分为若干个集群,它的核心思想就是使 ...

  7. GoF的23种设计模式之创建型模式的特点和分类

    创建型模式的主要关注点是“怎样创建对象?”,它的主要特点是“将对象的创建与使用分离”.这样可以降低系统的耦合度,使用者不需要关注对象的创建细节,对象的创建由相关的工厂来完成.就像我们去商场购买商品时, ...

  8. UserAgentUtils 获取浏览器信息

    <dependency> <groupId>eu.bitwalker</groupId> <artifactId>UserAgentUtils</ ...

  9. c#---Socean.RPC框架实测[并发量13w][响应时间0.04ms]

    目录1.高性能RPC框架:Socean.RPC 前言 经过一段时间的优化,Socean.RPC的性能又提高了一些,不过这差不多是socketAPM模型的极限了.本框架仅仅2000多行代码,无第三方框架 ...

  10. 聊聊Golang逃逸分析

    逃逸分析的概念,go怎么开启逃逸分析的log. 以下资料来自互联网,有错误之处,请一定告之. 什么是逃逸分析 wiki上的定义 在编译程序优化理论中,逃逸分析是一种确定指针动态范围的方法——分析在程序 ...