毕业到现在差不多有两年没有再用过struts了,看是能看懂了,就是如果按照自己的想法去实现一些功能的话,现在的记忆还有些欠缺,况且在学校没有网络,书上讲的又不全,所以视野很狭隘,很多东西似懂非懂,不怎么用。

废话少说。

struts中的html标签,比如说html:text,如果你想用js得到这个里面的值的话,就不能像得到普通html标签里的值一样了,因为这个标签里没有id或者name属性,代替id的是styleId,代替name的就是property属性。所以你想取得一个元素的值,就得这样写:

document.getElementById(‘styleId’).value;

相同的对于其他的html元素都可以这样实现。但是呢,还可以用另外一种方法来实现,因为通常我们都会用表单来处理一些数据,比如说html:form,当html:text里面不写styleId而只有property的话可以这样写:

document.forms[0].propertyName.value;

可以得到同样的效果。贴两段代码做比较:

一、

Java Server Page语言: Codee#8350
<table>
        <html:form action="/user/logon" focus="username">
          <tr><td><html:text property="username"/></td></tr>
          <tr><td><html:password property="userpasswd"/></td></tr>
          <tr>
           <td><html:button property="" value="submit"/></td>
           <td><html:reset value="reset"/></td>
          </tr>
        </html:form>
</table>
function  checkLogon(){
        var username=document.forms[0].username.value;
        var passwd=document.forms[0].userpasswd.value;
        if(username==null || username==”){
            alert(’请输入用户名!’);
            return false;
        }else if(passwd==null || passwd==”){
            alert(’请输入密码!’);
            return false;
        }else{
            document.forms[0].submit();
            return true;
        }
    }

二、

Java Server Page语言: Codee#8351
<table>
      <html:form styleId="logonForm" action="/user/logon" focus="username">
        <tr><td><html:text property="username" styleId="usernameId"/></td></tr>
        <tr><td><html:password property="userpasswd"   styleId="userpasswdId"/></td></tr>
        <tr>
          <td><html:button property="" value="submit"/></td>
          <td><html:reset value="reset"/></td>
        </tr>
      </html:form>
</table>
function  checkLogon(){
        var username=document.getElementById(’usernameId’).value;
        var passwd=document.getElementById(’userpasswdId’).value;
        if(username==null || username==”){
            alert(’请输入用户名!’);
            return false;
        }else if(passwd==null || passwd==”){
            alert(’请输入密码!’);
            return false;
        }else{
            document.getElementById(’logonForm’).submit();
            return true;
        }
    }

真不好用。。。

—-2009/05/20

Tags: , ,

Related posts

Tags: ,,.
Home

No Comments Now!

Be the first to comment on this entry.

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs must be fully qualified (eg: http://hanghang.name),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.