读书人

两次密码验证的有关问题

发布时间: 2012-02-06 15:52:44 作者: rapoo

两次密码验证的问题

<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 ";
}

读书人网 >JavaScript

热点推荐