我运用了或运算符,当我有输入了“学生学号”(name="num")的时候,为什么还会出现提示的呢?
  <script language="javascript">
function chkinput_login(form){
if((form.name.value=="") || (form.num.value=="")){
alert("请输入学生姓名或学生学号");
form.name.focus();
return(false);
}
  
}
  </script><form id="form2" method="GET" action="<?php ($_SERVER['PHP_SELF'])?>" onSubmit="return chkinput_login(this)">
<table width="100%" border="0" cellspacing="1" id="hcx">
<tr>
<td width="16%">
学生姓名:<input name="name" type="text" id="name" ><br>
学生学号:<input name="num" type="text">
         </td>
</tr>
</table>
</form>

解决方案 »

  1.   

    我运用了或运算符,当我有输入了“学生学号”(name="num")的时候,为什么还会出现提示的呢?就是因为或运算的问题,先了解或运算是什么
    可以用与运算对比一下
      

  2.   

    if((form.name.value=="") || (form.num.value=="")){
            alert("请输入学生姓名或学生学号");或运算: 只要有一个条件成立,就会执行alert()
    你只输入学号但姓名为空
    这里只能用与运算
      

  3.   


    明白啦,原来是自己搞错啦,哈哈,应该要用&&