【问题标题】:Struts2 html checkbox not pre-checked未预先检查 Struts2 html 复选框
【发布时间】:2016-01-08 04:13:35
【问题描述】:
<body>
    <h3>Register for a prize by completing this form.</h3>
    <s:form action="register">
          <s:textfield name="personBean.firstName" label="First name" />
          <s:textfield  name="personBean.lastName" label="Last name" />
          <s:textfield name="personBean.email"  label ="Email"/>
          <s:textfield name="personBean.age"  label="Age"  />
          <input type="checkbox" checked="checked" />
          <s:submit/>
    </s:form>
    <input type="checkbox" checked="checked" />
</body>

我有一个包含以上内容的jsp。表单内的复选框未选中,而表单外的复选框已预先选中。我在 Struts2 表单中混合了普通的 html 复选框和非 html 元素。

【问题讨论】:

    标签: html jsp checkbox struts2


    【解决方案1】:

    在这里,通过在表单中​​放置这样的输入标记,您的 html 格式不正确。

    要解决它,您可以使用 s:checkbox

    <s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing" value="true"/>
    

    【讨论】:

    • 您的 html 格式错误。这就是为什么检查不工作。
    • 感谢 Aleksandr M 指出这一点。我不知道这一点。我只是觉得把东西放在这样的桌子上很奇怪。
    • 现在,当您知道它为什么不起作用时,您可以给出正确的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2020-03-25
    相关资源
    最近更新 更多