input標簽獲取焦點時文本框內提示信息清空(並且變換文本框背景顏色)(2011-04-07 23:03:17)
主要是利用javascript中的觸發事件onfocus和onblur
<script language="javascript" type="text/javascript">
<!--
function myFocus(obj,color){
//判斷文本框中的內容是否是默認內容
if(obj.value=="請輸入收件人地址"){
obj.value="";
}
//設置文本框獲取焦點時候背景顏色變換
obj.style.backgroundColor=color;
}
function myblur(obj,color){
//當鼠標離開時候改變文本框背景顏色
obj.style.background=color;
}
在input標簽中
<input type="text" name="username" id="username" onfocus="myFocus(this,'#f4eaf1')" onblur="myblur(this,'white')" value="請輸入收件人地址"/>
用上述簡單方法可以做到文本框背景顏色的變換和提示信息的清除