日期:2014-05-18  浏览次数:20782 次

javascript带返回值的函数调用问题
test.htm:
<head>
      <title> JUST   A   TEST </title>
<script   language= "javascript ">
      function   testJs(){
      alert(document.form1.name1.value);
            if(document.form1.name1.value== " "){
                      alert( "ttt ");
                      return   false;
            }
          if(document.form1.name1.value== "jack "){
            alert( "ggg ");
            return   true;
        }
      }
    function   tt(){
          alert(form1.name1.value);
          return   false;
    }
</script>
</head>

<body>
      <form   name= "form1 "   action= "tt.html "   >
            <input   type= "text "   name= "name1 "   />
            <input   type= "submit "   onclick= "testJs(); "   />
      </form>
</body>

</html>
用onclick调用testJs()时,判断语句都执行了,但是无论name1的value为null还是jack
都转到了tt.html页面.
不知道是那里出了问题,谢谢高手指点!!!!

------解决方案--------------------
根本不需要再用onclick()了.你已经是submit按钮了.直接写:
<form name= "form1 " action= "tt.html " onsubmit= "return testJs(); ">
就OK了.