首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

两次密码验证的有关问题

2012-02-06 
两次密码验证的问题htmlxmlns http://www.w3.org/1999/xhtml headmetahttp-equiv Content-Type

两次密码验证的问题

<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>

</head>

<body>


<FORM   METHOD=POST   ACTION= " ">
  <p>
        <input   type= "password "   id= "input1 ">
</p>
       
<p>
 
        <input   type= "password "   id= "input2 "   onBlur= "check() ">
</p>
  <div   id= "layer1 "   style= "position:absolute;width:236px;height:15px;left:179px;top:57px;background-color:#EBE9ED;visibility:hidden "> √ </div>
 
    <div   id= "layer2 "   style= "position:absolute;width:236px;height:15px;left:179px;top:57px;background-color:#EBE9ED;visibility:hidden "> X </div>
   
</FORM>


</body>

<script>
function   check()
{  
layer1.style.visibility= "hidden "
layer2.style.visibility= "hidden "

with(document.all){
if(input1.value!=input2.value)
{
layer2.style.visibility= "visible ";
//input1.value   =   " ";
//input2.value   =   " ";
}
else   layer1.style.visibility= "visible ";
}
if(input1.value==input2.value)
{
input1.value   =   " ";
input2.value   =   " ";
layer2.style.visibility= "visible ";
}

}
</script>
</html>


怎样才能在两个输入框为空值时,不调用layer1。而是提示输入信息。

[解决办法]
with(document.all){
if(input1.value!=input2.value)
{
layer2.style.visibility= "visible ";
//input1.value = " ";
//input2.value = " ";
}
else if (input1.value == " ")
{
alert( "不能为空 ");
}
else layer1.style.visibility= "visible ";
}

热点排行