java-在使用struts html标记时,如何使用文本框的property属性获取文本框的值?还有其他获取价值的方法吗?

    function validate(){
    var username = document.getElementByProperty("userName").value;
    var password = document.getElementByProperty("passWord").value;
    if((username == null ||username =='') || (password == null||password=='')){
     x=document.getElementById("error");
     x.innerHTML = "Username or Password Cannot Be Blank";
    else{
       document.getElementById("loginform").submit();
    }


    <form id="loginform" action="login.do" method="post">
    UserName:<html:text property="userName"></html:text>
    PassWord:<html:password property="passWord"></html:password>
    <html:button onclick="validate()"></html:button>
    </form>

上面的代码无法正常工作,我无法在文本框中获取值进行验证…请帮助我解决此问题…

解决方法:

function validate(){
    var username = document.getElementById("userName").value;
    var password = document.getElementById("passWord").value;
}


<form id="loginform" action="login.do" method="post">
    UserName:<html:text property="userName" styleId="userName"></html:text>
    PassWord:<html:password property="passWord" styleId="passWord"></html:password>
    <html:button onclick="validate()"></html:button>
</form>
上一篇:对象实例化时的java.lang.NullPointerException


下一篇:JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo