一个通用的动态控制表单默认值的jscript方法,简单,很实用
<script type="text/javascript">
function validForms(){
if(!document.getElementById) return false;
var initform=document.getElementById("initform");
for(var i=0,valids=initform.elements;i<valids.length;i++){
if(valids[i].type=='submit') continue;
valids[i].onfocus=function(){
if(this.value==this.defaultValue){
this.value='';
this.style.color='#000';
}
}
valids[i].onblur=function(){
if(this.value==''){
this.value=this.defaultValue;
this.style.color='#dfdfdf';
this.parentNode.onsubmit=function(){return false;}
}
}
}
}
window.onload=validForms;
</script>
function validForms(){
if(!document.getElementById) return false;
var initform=document.getElementById("initform");
for(var i=0,valids=initform.elements;i<valids.length;i++){
if(valids[i].type=='submit') continue;
valids[i].onfocus=function(){
if(this.value==this.defaultValue){
this.value='';
this.style.color='#000';
}
}
valids[i].onblur=function(){
if(this.value==''){
this.value=this.defaultValue;
this.style.color='#dfdfdf';
this.parentNode.onsubmit=function(){return false;}
}
}
}
}
window.onload=validForms;
</script>
把上面代码放到页面head内即可!