大家好,小弟初来乍到。写一遮罩层,脑钝。望解决,谢过。
为了简单,我把代码主要部分贴出来
function show(){
......document.getElementById(‘最上面一层的ID’).innerHTML="....<input type='password' name='userpassowrd1'> <input type='userpassword' name='userpassword2'>"......
}
show()的作用是弹出遮罩层 以及背景层
然后写下面一段话
 function check(){
    if(document.getElementsByName("userpassword1").value ==document.getElementsByName("userpassword2").value)
    {
     alert("两次密码输入一致");
    }
     else
     {
     alert("两次密码输入不一致");
     show();
     }
}
然后小弟两个密码框不管输入什么  都显示密码一致    不执行show()\
然后将代码改成   
 if(document.getElementsByName("userpassword1").value ==document.getElementsByName("userpassword2").value)
    {
     alert("两次密码输入不一致"); 
    }
     else
     {
     alert("两次密码输入一致");
     show();
     }
    }
   弹出了不一致  但是执行了show
其他代码都没有问题  我都测试过了  
求解  在此谢过

解决方案 »

  1.   

    忘说了,check()  是 submit 按钮触发的事件   在innerHTML里面
      

  2.   

    这样的问题没法回答啊~~~~没有细致去研究源代码是回答不了的,"弹出了不一致 但是执行了show"建议你在其它分支判断中再研究下
      

  3.   

        function show(){
        var a=document.getElementById("background");
        a.style.display="";
        a.style.filter ="Alpha(Opacity=50)"; 
        document.getElementById("vista").style.display="";
        document.getElementById("vista").innerHTML="<table style='color:White;font-size:20px;width:500px;height:50px;background-color:#0099FF'><tr style='margin:10px;'><td>网站注册</td><td align='right'><a onclick='hiden()'><img src='img/x.gif' /></a></td></tr></table><table style='margin:60px auto;'><tr><td>用户名</td><td><input type='text' name='userName'></td></tr><tr><td>密 码</td><td><input type='password' name='userpassword1' style='height:16px;width:150px'></td></tr><tr><td>重复密码</td><td><input type='password' name='userpassword2' style='height:16px;width:150px'></td><tr><tr align='center'><td><input type='submit' onclick='check()' value='注册'/></td><td ><input type='button' value='退出' onclick='hiden()'></td></tr></table>";
        }
         function hiden() {
                   document.getElementById("vista").style.display = "none";
                   document.getElementById("background").style.display="none";
               }
        function check(){
        if(document.getElementsByName("userpassword1").value ==document.getElementsByName("userpassword2").value)
        {
         alert("两次密码输入不一致"); 
        }
         else
         {
         alert("两次密码输入一致");
         show();
         }
        }
    vista   为前景div   ID
    background 为背景div的ID
      

  4.   

    document.getElementsByName("userpassword1").value ==document.getElementsByName("userpassword2").value这个因为都获取的不到值所以两个值都一个样,都是空的,不奇怪,但是你的第二个就不知道了,弹出了不一致 但是执行了show?除非是其他地方调用了,不然应该不会执行show啊
      

  5.   

    楼主先获取userpassword后有userpassword的input是获取不到东西的
      

  6.   

    良心地说,不要用css 滤镜什么的去制作什么遮盖层,直接用一张1*1像素的24 png去平铺遮盖,效果更好.
      

  7.   

    饿   小弟愚钝  只是感觉  我先执行show  然后呢   那段代码就会有了  然后就有name='password1'这个input的控件了  然后执行check() getelemntbuname取值  不过楼上说得很对啊   
      

  8.   

    那请问小弟该怎么解决获取 password控件的 值来判断呢
      

  9.   

    将<table style='color:White;font-size:20px;width:500px;height:50px;background-color:#0099FF'><tr style='margin:10px;'><td>网站注册</td><td align='right'><a onclick='hiden()'><img src='img/x.gif' /></a></td></tr></table><table style='margin:60px auto;'><tr><td>用户名</td><td><input type='text' name='userName'></td></tr><tr><td>密 码</td><td><input type='password' name='userpassword1' style='height:16px;width:150px'></td></tr><tr><td>重复密码</td><td><input type='password' name='userpassword2' style='height:16px;width:150px'></td><tr><tr align='center'><td><input type='submit' onclick='check()' value='注册'/></td><td ><input type='button' value='退出' onclick='hiden()'></td></tr></table>
    直接写到html中(visat)然后让其(visat)隐藏show的时候让他显示就行了,这样就能获取到值了
      

  10.   

    最好设置个ID 用 dicument.getElementById("").value
    不然这样:
    document.getElementsByName("userpassword1")[0].value==document.getElementsByName("userpassword2")[0].value
    如果你的Name唯一应该也可以
      

  11.   

    if(document.getElementsByName("userpassword1").value ==document.getElementsByName("userpassword2").value)
      {
      alert("两次密码输入不一致");  
    return;
      }
      else
      {
      alert("两次密码输入一致");
      show();
      }
      }
      

  12.   

    情况是这样的    
      同在一个JS文件中    
      两个不同的函数  一个函数如何调用另外一个函数里面的控件   getelementById  貌似都没用