lz要测试一下看是哪一步出了问题啊。你的代码我们没法测试。你看看是否得到了user_namepy这个对象。如果没有建议考虑使用<html:text styleId="myId"/> ,然后在js中document.getElementById("myId");得到。如果得到了看看你的trimString函数是否正确返回。

解决方案 »

  1.   

    你看看这个,希望你能明白
    <script type="text/javascript">
    function check(){
    if(teamForm.playerName.value=="")//在这里,你的Form的名字应该是这样的
    {
    alert('球员姓名不能为空');
    teamForm.playerName.focus();
    return false;
    }
    return true;
    }
    </script>
    <html:html lang="true">
      <head>
        <html:base />
        
        <title>playerAdd</title>   </head>
      
      <body>
        <html:form action="team.do?method=doAdd" method="post" focus="playerName" onsubmit="return check()">
          <table border="0">
            <tr>
              <td>playerName:</td>
              <td><html:text property="playerName" /></td>
            </tr>
            <tr>
              <td>playerSex:</td>
              <td><html:radio property="playerSex" value="M" />男<html:radio property="playerSex" value="F" />女</td>
            </tr>
            <tr>
            <td>playerAge: </td>
            <td><html:text property="playerAge"></html:text> </td>
            </tr>
            <tr>
            <td>teamId </td>
            <td>
            <html:select property="teamId">
            <html:options collection="teamNameList" property="teamId" labelProperty="teamName" />
            </html:select> </td>
            </tr>
            <tr>
              <td colspan="2" align="center"><html:submit /></td>
            </tr>
          </table>
        </html:form>
      </body>
    </html:html>
        
      

  2.   

    在struts上中, Form的名字,也可以这样 form1 = document.forms[0];
    form的名字是以数组的形式出现的了,这也是个人看法,希望对你有所帮助
      

  3.   

    问题已经解决!我用的是document.all['user_namepy'].value。