欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS清除文本框內(nèi)容離開(kāi)在恢復(fù)及鼠標(biāo)離開(kāi)文本框時(shí)觸發(fā)js的方法

 更新時(shí)間:2016年01月12日 09:05:07   作者:一落葉而知秋  
多網(wǎng)站的需要填寫(xiě)的文本框在默認(rèn)狀態(tài)下都會(huì)給出一個(gè)默認(rèn)的提示語(yǔ)言,當(dāng)鼠標(biāo)點(diǎn)擊此文本框的時(shí)候能夠?qū)⒗锩娴哪J(rèn)文本清除,當(dāng)刪除輸入的文本且焦點(diǎn)離開(kāi)文本框的時(shí)候再將默認(rèn)的文本寫(xiě)入文本框

多網(wǎng)站的需要填寫(xiě)的文本框在默認(rèn)狀態(tài)下都會(huì)給出一個(gè)默認(rèn)的提示語(yǔ)言,當(dāng)鼠標(biāo)點(diǎn)擊此文本框的時(shí)候能夠?qū)⒗锩娴哪J(rèn)文本清除,當(dāng)刪除輸入的文本且焦點(diǎn)離開(kāi)文本框的時(shí)候再將默認(rèn)的文本寫(xiě)入文本框。

代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>點(diǎn)擊文本框清除默認(rèn)值</title>
<script type="text/javascript"> 
window.onload=function()
{
var username=document.getElementById("username");
username.onclick=function()
{
if(username.value=="請(qǐng)輸入您的姓名")
{
username.value="";
this.focus();
}
}
username.onblur=function()
{
if(username.value=="")
{
username.value="請(qǐng)輸入您的姓名";
}
}
}
</script>
</head>
<body>
<input type="text" value="請(qǐng)輸入您的姓名" id="username" />
</body>
</html> 

以上代碼實(shí)現(xiàn)了我們的要求,當(dāng)點(diǎn)擊文本框的時(shí)候能夠清除文本框中的內(nèi)容,如果文本框沒(méi)有輸入任何內(nèi)容,這個(gè)時(shí)候鼠標(biāo)焦點(diǎn)離開(kāi)文本框的時(shí)候,會(huì)將文本框的值恢復(fù)到默認(rèn)狀態(tài)。不過(guò)如果密碼框肯恩有點(diǎn)麻煩,因?yàn)槊艽a框并非顯示的明文,解決方案可以參閱JavaScript實(shí)現(xiàn)輸入框(密碼框)出現(xiàn)提示語(yǔ)一章節(jié)。

鼠標(biāo)離開(kāi)文本框時(shí)觸發(fā)js的方法

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="textBox.WebForm1" %> 
<!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 runat="server"> 
<title></title> 
<script type="text/javascript"> 
function validate() { 
var name = document.getElementById("txtName"); 
if (name.value == 2) { 
alert("你必須不是二!"); 
name.focus(); 
return false; 
} 
return true; 
} 
</script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
<asp:TextBox ID="txtName" onblur="validate();" runat="server" /> 
</div> 
</form> 
</body> 
</html> 

相關(guān)文章

最新評(píng)論