<html>
<head><title>javascript实现文本框默认内容Demo</title>
<script type="text/javascript">
window.οnlοad=function(){
document.getElementById("txtSearch").οnfοcus=function(){
if(this.value="DefaultKey"){
this.value='';
}
};
document.getElementById("txtSearch").οnblur=function(){
if(!this.value){
this.value='DefaultKey';
}
};
}
//显示搜索的关键词
function showSearch(){
var keyword=document.getElementById("txtSearch").value;
var result=document.getElementById("txtResult");
result.firstChild.nodeValue=keyword;
}
</script>
<style type="text/css">
p{
display:inline;
}
.default{
color:#ccc;
}
</style>
</head>
<body>
<input type="text" id="txtSearch" value="DefaultKey" class="default"/>
<input type="button" id="btnSearch" value="Search" οnclick="showSearch()">
<p>SerachedKeyword:</p><p id="txtResult">Result</p>
</body>
</html>