预览:

不知道为什么下面这个窗口中的 JavaScript 代码没有运行-_-||,想看实际效果就把下面的代码保存下来打开看吧。

代码:

<!DOCTYPE HTML>
<html lang="ZH-CN" dir="ltr">
<head>
<title></title>
<style>
* {
line-height: 142%;
} html {
overflow: auto;
} div.textbox, select {
width: 320px;
/*以下两个属性在实际使用时需要去掉*/
margin-top:20px;
margin-left:20px;
} div.textbox > div {
margin-bottom: 8px;
} body {
margin: 0;
font-family: "Microsoft Yahei UI","Microsoft Yahei",Verdana,Simsun,"Segoe UI","Segoe UI Web Regular","Segoe UI Symbol","Helvetica Neue","BBAlpha Sans","S60 Sans",Arial,sans-serif;
color: #000;
background-color: #fff;
background-image: none;
background-repeat: repeat;
background-position: top left;
direction: ltr;
font-size: 88%;
-webkit-font-smoothing: antialiased;
} input, select, textarea, button {
font-size: 100%; outline:none;
font-family: "Microsoft Yahei UI","Microsoft Yahei",Verdana,Simsun,"Segoe UI","Segoe UI Web Regular","Segoe UI Symbol","Helvetica Neue","BBAlpha Sans","S60 Sans",Arial,sans-serif;
} input[type=text], input[type=password], input[type=email], input[type=tel] {
ime-mode: inactive;
} input[type=email], .ltr_override {
direction: ltr;
} input[type=text], input[type=password], input[type=email], input[type=tel] {
padding: 4px 8px;
height: 1.46em;
width: 302px; /* padding-left 和 padding-right 为 8+8 还有 border-left 和 border-right 为 1 + 1 ,所以 width 为 320 - 16 - 2 */
} input[type=text], input[type=password], input[type=email], input[type=number], input[type=tel], input[type=search], textarea {
width: 18.54em;
padding: 4px 8px;
font-family: "Microsoft Yahei UI","Microsoft Yahei",Verdana,Simsun,"Segoe UI","Segoe UI Web Regular","Segoe UI Symbol","Helvetica Neue","BBAlpha Sans","S60 Sans",Arial,sans-serif;
font-size: 100%;
color: #212121;
border: 1px solid #bababa;
background-color: rgba(255,255,255,.8);
filter:Alpha(opacity=80);
} input[type=text], input[type=password], input[type=email], input[type=number], input[type=tel], input[type=search] {
height: 1.57em;
} input[type=text], input[type=password], input[type=email], input[type=tel] {
width: 302px;
} div.placeholder {
color: #666;
background-color: transparent;
margin-top: 7px; margin-top:6px \9;
margin-left: 9px;
white-space: nowrap;
} div.ltr_override.placeholder {
margin-left: 9px;
margin-right: auto;
text-align: left;
}
</style>
<script type="text/javascript">
function InpFocus(obj) {
var login = obj; login.style.border = "1px solid #999";
}
function InpBlur(obj) {
var login = obj; login.style.border = "1px solid #bababa";
}
function InpKeypress(obj) {
var login = obj; if (login.value === "" && window.event.keyCode === 8) return; var placeHolder = login.nextElementSibling || util.getNextSibling(login.nextSibling); placeHolder = util.getDomNode(placeHolder.childNodes); placeHolder.innerText = "";
}
function InpKeyup(obj) {
var login = obj;
var placeHolder = login.nextElementSibling || util.getNextSibling(login.nextSibling); placeHolder = util.getDomNode(placeHolder.childNodes); if (login.value === "") {
placeHolder.innerText = "用户名"
} else {
placeHolder.innerText = ""
}
} var util = {
getNextSibling: function (node) {
var n = node; while (n.nodeType != 1) {
n = n.nextElementSibling || n.nextSibling;
} return n;
},
getDomNode: function (arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].nodeType === 1) return arr[i];
}
}
};
</script>
</head> <body>
<div class="textbox">
<div style="width: 100%; position: relative;">
<input id="login" name="login" class="ltr_override" type="text" style="position:relative; z-index:6;" autocomplete="off"
onfocus="InpFocus(this);" onblur="InpBlur(this);" onkeypress="InpKeypress(this);" onkeyup="InpKeyup(this);" />
<div class="phholder" style="left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5;">
<div class="placeholder ltr_override" aria-hidden="true" style="cursor: text;">用户名</div>
</div>
</div>
</div>
</body>
</html>

一个漂亮的 PlaceHolder的更多相关文章

  1. 一个漂亮的js表单验证页面+验证码

    一个漂亮的js表单验证页面 见图知其意, 主要特性 带密码安全系数的判断 其他的就没有啥啦 嘿嘿嘿 当然,其代码也在Github上 我也准备了一套可以直接Ctrl + v; Ctrl + c 运行的代 ...

  2. ctex moderncv版本更新--用latex写一个漂亮的简历

    我的电脑是win7系统32位,ctex版本是v2.9.2.164 full(http://www.ctex.org/CTeXDownload) 一直不太清楚moderncv里面类似\cventry这种 ...

  3. PS网页设计教程XXIV——从头设计一个漂亮的网站

    作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...

  4. 分享一个漂亮的ProgressBar控件

    codeprject上看到的一个漂亮的ProgressBar控件.是用vb.net开发的. C#直接在工具箱中引用即可. 地址:http://www.codeproject.com/Articles/ ...

  5. 小强的HTML5移动开发之路(5)——制作一个漂亮的视频播放器

    来自:http://blog.csdn.net/dawanganban/article/details/17679069 在前面几篇文章中介绍了HTML5的特点和需要掌握的基础知识,下面我们开始真正的 ...

  6. 一个漂亮的php验证码类

    一个漂亮的php验证码类(分享)   作者: 字体:[增加 减小] 类型:转载 下面小编就为大家分享一个漂亮的php验证码类.需要的朋友可以过来参考下   直接上代码: 复制代码 代码如下: //验证 ...

  7. 给Ajax一个漂亮的嫁衣——Ajax系列之五(下)之序列化和反序列化

    给Ajax一个漂亮的嫁衣——Ajax系列之五(下)之序列化和反序列化 标签: ajaxdictionaryjsonobject服务器function 2012-07-25 18:41 2242人阅读  ...

  8. 一个漂亮而强大的自定义view

    代码地址如下:http://www.demodashi.com/demo/13502.html 简介 主要提供一个漂亮而强大的自定义SeekBar,进度变化由提示牌 (sign)展示,具有强大的属性设 ...

  9. 一个漂亮而强大的RecyclerView

    代码地址如下:http://www.demodashi.com/demo/13470.html 简介 主要提供了简单易用强大的RecyclerView库,包括自定义刷新加载效果.极简通用的万能适配器A ...

随机推荐

  1. pthread mutex

    pthead_mutex_t mutex; 1:create: pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t ...

  2. Python ————反射机制

    python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,改四个函数分别用于对对象内部执行:检查是否含有某成员.获取成员.设置成员.删除成员. ...

  3. redis 过期时间与缓存

    设置过期时间 redis对于存储的键值可以设置过期时间,对于过期了的键值,redis会自动删除. > OK > get price " > expire price (in ...

  4. Microsoft Visual Studio正在等待操作完成

    在编译项目的时候,有时会遇到 Microsoft Visual Studio正忙,结果就是半天没反应,要等待很长时间才能编译完成,在网上查了一下资料,微软官方是这样解释的: 阻止某些 devenv.e ...

  5. mock生成随机数的各种情况

    [发现一篇好的文章,用来自己作参考] 接口测试时需要生成各种正则表达式的随机数进行边界值测试,字符串测试等: 比如生成数字,字母,邮箱,一段中文,一段英文 推荐1:生成随机数的多种情况 http:// ...

  6. 简单说明一下Token ,Cookie,Session

    在Web应用中,HTTP请求是无状态的.即:用户第一次发起请求,与服务器建立连接并登录成功后,为了避免每次打开一个页面都需要登录一下,就出现了cookie,Session. Cookie Cookie ...

  7. ES6学习笔记<一> let const class extends super

    学习参考地址1  学习参考地址2 ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015:也 ...

  8. C#取整函数Math.Round、Math.Ceiling和Math.Floor

    1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...

  9. 【sql小坑】在group by里用select字段的别名?

    背景 -- 求每个用户的拥有的产品数,其中userid需要简单split出来 SELECT split (id, '-') [ 0 ] AS userid, count(DISTINCT produc ...

  10. 学习笔记:jqchart

    (Highcharts 167K:  ECharts 354K: jqChart 240K),如果用于网络,Highchart最小 jqchart 国外的一个图表库 挺漂亮的 http://www.j ...