【问题标题】:While using struts html tags, How do I get the value of a textbox using its property attribute? Is there any other way to get the value?使用 struts html 标签时,如何使用其属性属性获取文本框的值?有没有其他方法可以获取价值?
【发布时间】:2013-07-19 09:27:48
【问题描述】:
    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>

上面的代码不起作用,我无法获取文本框中的值进行验证...请帮助我解决这个问题...

【问题讨论】:

    标签: java javascript jsp struts


    【解决方案1】:
    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>
    

    【讨论】:

    • 感谢您回复 Mr.Reddy... 但是,Struts-html 标签没有 'id' 属性,这就是为什么我要从属性属性中获取值。
    • 我猜 Struts 有 styleId 而不是“id”。更新了我的答案
    • 非常感谢 Reddy 先生...我已经使用 'styleid' 进行了检查,它正在工作...谢谢!
    【解决方案2】:

    在阅读下一行之前,请安装好的网络检查器。 例如

  • Firefox 中的萤火虫
  • Chrome 中的 Web 检查器
  • IE Web 检查器
  • 并检查源代码

    或者你可以查看源代码。

       1. document.getElementsByName("userName")[0].value;
       2. document.getElementById("userName").value;
       3. document.forms["loginform"]["userName"].value
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-07
      • 2020-08-05
      • 2017-11-16
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 2019-06-11
      相关资源
      最近更新 更多