博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ie8的input的placeholder不显示的解决bug
阅读量:4631 次
发布时间:2019-06-09

本文共 1718 字,大约阅读时间需要 5 分钟。

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery1.10.2.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
.input-item {
position: relative;
margin: 10px;
}
.pwd-place {
position: absolute;
top: 0;
left: 72px;
width: 100%;
height: 100%;
font-size: 12px;
}
</style>
</head>
<body>
<form action="#">
<div class="input-item">
<label for="userName">用户名:</label>
<input class="username" id="userName" type="text" placeholder="请输入用户名">
</div>
<div class="input-item">
<label for="pwd">密码:</label>
<input class=" password" id="pwd" type="password" placeholder="请输入密码">
<span class="pwd-place"></span>
</div>

</form>

<script src="jquery-1.11.3.js"></script>
<script>
function placeholder(el){

function isPlaceholer(){

var input = document.createElement("input");
return "placeholder" in input;
}

var $el = $(el);

if( isPlaceholer()==false && !('placeholder' in document.createElement('input')) ){

$('input[placeholder],textarea[placeholder]').each(function(){

var that = $(this),
text= that.attr('placeholder');
if(that.val()===""){
if(that.attr("type") == "password"){
$el.html("请输入密码");
}else {
that.val(text).addClass('placeholder');
}
}
that.focus(function(){
if($el.html() == text){
$el.html("");
}
if(that.val()===text) {
that.val("").removeClass('placeholder');

}

})
.blur(function(){
if(that.val()==="") {
if (that.attr("type") == "password") {
$el.html("请输入密码");

}else {

that.val(text).addClass('placeholder');
}
}
})
.closest('form').submit(function(){
if(that.val() === text){
that.val('');
}
});
});
}
}
$(document).ready(function() {
placeholder(".pwd-place")
});
</script>
</body>
</html>

转载于:https://www.cnblogs.com/yangwan/p/10572906.html

你可能感兴趣的文章
VC调用MATLAB
查看>>
[转载]线上应用故障排查之一:高memory占用
查看>>
vs中的主题配置
查看>>
DDD开发框架ABP之本地化/多语言支持
查看>>
win server 2008配置ftp无法登陆问题的解决办法
查看>>
Graphics优化策略-官篇3
查看>>
(转)javascript深入理解js闭包
查看>>
JS关闭当前父级div
查看>>
Spring事务事件监控
查看>>
Coding 代码push/commit/pull/git clone
查看>>
算法基础
查看>>
找出第二大的数
查看>>
第五周进度条
查看>>
nc命令
查看>>
工作流模块界面打开报错
查看>>
一点不懂到小白的linux系统运维经历分享
查看>>
asp.net IE10 下的bug
查看>>
grep的小技巧
查看>>
maven install 打包 报错 Cannot run program "gpg.exe": CreateProcess error
查看>>
abstract类中method
查看>>