国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

兩種方法實現文本框輸入內容提示消失

2024-05-06 14:19:19
字體:
來源:轉載
供稿:網友
第一種方法:
基于HTML5 input標簽的新特性 - placeholder 。另外,x-webkit-speech 屬性可以實現語音輸入功能。
代碼如下:
<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里的內容顯示隱藏。
代碼如下:
<!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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 会东县| 武乡县| 濮阳市| 永修县| 宝丰县| 石景山区| 宝山区| 桐梓县| 金平| 九龙县| 丁青县| 甘孜县| 汽车| 页游| 石嘴山市| 蒲城县| 万州区| 巴青县| 方城县| 钦州市| 社旗县| 乐清市| 柳州市| 额济纳旗| 连南| 阳春市| 新乐市| 五指山市| 县级市| 榆林市| 紫云| 夏津县| 信丰县| 陈巴尔虎旗| 泰顺县| 荆门市| 桃园市| 乐平市| 林周县| 珠海市| 揭西县|