兩種方法實現(xiàn)文本框輸入內(nèi)容提示消失
更新時間:2013年03月17日 09:48:14 作者:
第一種方法:基于HTML5 input標簽的新特性 - placeholder 。另外,x-webkit-speech 屬性可以實現(xiàn)語音輸入功能;第二種方法:
用span模擬,定位span,借助JS鍵盤事件判斷輸入,確定span里的內(nèi)容顯示隱藏
第一種方法:
基于HTML5 input標簽的新特性 - placeholder 。另外,x-webkit-speech 屬性可以實現(xiàn)語音輸入功能。
<div><input type="email" name="email" spellcheck="false" placeholder="郵 箱" autofocus tabindex="1" x-webkit-speech></div>
<div><input type="password" name="password" placeholder="密 碼" tabindex="2"></div>
第二種方法:
用span模擬,定位span,借助JS鍵盤事件判斷輸入,確定span里的內(nèi)容顯示隱藏。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#focus .input_txt").each(function(){
var thisVal=$(this).val();
//判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
if(thisVal!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
//聚焦型輸入框驗證
$(this).focus(function(){
$(this).siblings("span").hide();
}).blur(function(){
var val=$(this).val();
if(val!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
});
})
$("#keydown .input_txt").each(function(){
var thisVal=$(this).val();
//判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
if(thisVal!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
$(this).keyup(function(){
var val=$(this).val();
$(this).siblings("span").hide();
}).blur(function(){
var val=$(this).val();
if(val!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
})
})
})
</script>
<style type="text/css">
form{width:400px;margin:10px auto;border:solid 1px #E0DEDE;background:#FCF9EF;padding:30px;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;}
label{display:block;height:40px;position:relative;margin:20px 0;}
span{position:absolute;float:left;line-height:40px;left:10px;color:#BCBCBC;cursor:text;}
.input_txt{width:398px;border:solid 1px #ccc;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;height:38px;text-indent:10px;}
.input_txt:focus{box-shadow:0 0 4px rgba(255,153,164,0.8);border:solid 1px #B00000;}
.border_radius{border-radius:5px;color:#B00000;}
h2{font-family:"微軟雅黑";text-shadow:1px 1px 3px #fff;}
</style>
</head>
<body>
<form class="border_radius" id="focus">
<h2>聚焦型提示語消失</h2>
<label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius" /></label>
<label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
</form>
<form class="border_radius" id="keydown">
<h2>輸入型提示語消失</h2>
<label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius" /></label>
<label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
</form>
</body>
</html>
基于HTML5 input標簽的新特性 - placeholder 。另外,x-webkit-speech 屬性可以實現(xiàn)語音輸入功能。
復制代碼 代碼如下:
<div><input type="email" name="email" spellcheck="false" placeholder="郵 箱" autofocus tabindex="1" x-webkit-speech></div>
<div><input type="password" name="password" placeholder="密 碼" tabindex="2"></div>
第二種方法:
用span模擬,定位span,借助JS鍵盤事件判斷輸入,確定span里的內(nèi)容顯示隱藏。
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#focus .input_txt").each(function(){
var thisVal=$(this).val();
//判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
if(thisVal!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
//聚焦型輸入框驗證
$(this).focus(function(){
$(this).siblings("span").hide();
}).blur(function(){
var val=$(this).val();
if(val!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
});
})
$("#keydown .input_txt").each(function(){
var thisVal=$(this).val();
//判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
if(thisVal!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
$(this).keyup(function(){
var val=$(this).val();
$(this).siblings("span").hide();
}).blur(function(){
var val=$(this).val();
if(val!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
})
})
})
</script>
<style type="text/css">
form{width:400px;margin:10px auto;border:solid 1px #E0DEDE;background:#FCF9EF;padding:30px;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;}
label{display:block;height:40px;position:relative;margin:20px 0;}
span{position:absolute;float:left;line-height:40px;left:10px;color:#BCBCBC;cursor:text;}
.input_txt{width:398px;border:solid 1px #ccc;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;height:38px;text-indent:10px;}
.input_txt:focus{box-shadow:0 0 4px rgba(255,153,164,0.8);border:solid 1px #B00000;}
.border_radius{border-radius:5px;color:#B00000;}
h2{font-family:"微軟雅黑";text-shadow:1px 1px 3px #fff;}
</style>
</head>
<body>
<form class="border_radius" id="focus">
<h2>聚焦型提示語消失</h2>
<label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius" /></label>
<label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
</form>
<form class="border_radius" id="keydown">
<h2>輸入型提示語消失</h2>
<label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius" /></label>
<label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
</form>
</body>
</html>
相關文章
JS統(tǒng)計Flash被網(wǎng)友點擊過的代碼
JS統(tǒng)計Flash被網(wǎng)友點擊過的代碼...2007-05-05微信小程序云開發(fā)實現(xiàn)云數(shù)據(jù)庫讀寫權限
這篇文章主要為大家詳細介紹了微信小程序云開發(fā)實現(xiàn)云數(shù)據(jù)庫讀寫權限,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05

將函數(shù)的實際參數(shù)轉換成數(shù)組的方法
實際參數(shù)在函數(shù)中我們可以使用 arguments 對象獲得 (注:形參可通過 arguments.callee 獲得),雖然 arguments 對象與數(shù)組形似,但仍不是真正意義上的數(shù)組。
2010-01-01