onclick="submitForm(document.selectname)"放到<FORM name="selectname" METHOD="POST">中

解决方案 »

  1.   

    <script language="javascript">
    function submitForm() {
    var a=document.selectname;
        if (a.username.value== "") {
            window.alert("用户名不能为空!");
            return false;
        } else {
            frm.action = "keepon.jsp";
            frm.submit();
            return true;
        }
    }  
    </script><FORM name="selectname" METHOD="POST" onsubmit="return(submitForm())">
    <tr>
      <td>
        <INPUT TYPE="text" NAME="username" SIZE="20" MAXLENGTH="20">
      </td>
      <td>
    <input name="gonextpage" type="image" src="/images/gonextpage.gif" border="0" >
      </td>
    </tr>
    </form>
      

  2.   

    <body>
    <script language="javascript">
    function submitForm(frm) {
        if (frm.username.value == "") {
            window.alert("用户名不能为空!");
            return false
        } else {
            frm.action = "keepon.jsp";
            return true
        }
    }  
    </script><FORM name="selectname" METHOD="POST" target="_blank" onsubmit="return submitForm(this)">
    <table>
    <tr>
      <td>
        <INPUT TYPE="text" NAME="username" SIZE="20" MAXLENGTH="20">
      </td>
      <td>
        <input name="gonextpage" type="image" src="/images/gonextpage.gif" border="0">
      </td>
    </tr>
    </form>
      

  3.   

    <script language="javascript">
    function submitForm() {
    var a=document.selectname;
        if (a.username.value== "") {
            window.alert("用户名不能为空!");
            return false;
        } else {
            frm.action = "keepon.jsp";
            frm.submit();
            return true;
        }
    }  
    </script><FORM name="selectname" METHOD="POST" onsubmit="return(submitForm())" onkeydown="if(event.keyCode==13)this.submit();">
    <tr>
      <td>
        <INPUT TYPE="text" NAME="username" SIZE="20" MAXLENGTH="20">
      </td>
      <td>
    <input name="gonextpage" type="image" src="/images/gonextpage.gif" border="0">
      </td>
    </tr>
    </form>
      

  4.   

    沒有,這裡不會刷新的你把我的代碼全部copy 運行看看
    就是要return false