JS表单失去焦点时输入提示(onblur和this实例)


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS表单失去焦点时输入提示(onblur和this实例)</title>
<script type="text/javascript">
function blurx(obj,spanId,spanNoticeContent){
    var spanx=document.getElementById(spanId);
    var len=obj.value.length;
    //alert(len);
    if(len<=0){
        spanx.innerHTML=spanNoticeContent;
        spanx.style.color='#ff0000';
    }
    else{
        spanx.innerHTML='已经输入';
        spanx.style.color='#008000';
    }
}
</script>

网址<input type="text" name="inputName1" onblur="blurx(this,'spanId1','请输入网址')" /><span id="spanId1"></span>
<hr />


邮箱<input type="text" name="inputName2" onblur="blurx(this,'spanId2','请输入邮箱')" /><span id="spanId2"></span>




程序运行结果如下,点击这里亲自运行看看