1

首先,我没有编写此代码,也不是 Java 程序员,我只是将其从“反馈表单”页面修改为“请求表单”页面。我的目标是禁用提交按钮并提醒用户需要勾选复选框和/或在未选中复选框时阻止它提交数据。尽可能地,我想避免使用 javascript。

这是代码片段:

    public Serializable getKey() {

    String email = parameters.getParameter("email", "");
    String message = parameters.getParameter("message", "");
    String page = parameters.getParameter("page", "unknown");

    return HashUtil.hash(email + "-" + message + "-" + page);
}

/**
 * Generate the cache validity object.
 */
public SourceValidity getValidity() {
    return NOPValidity.SHARED_INSTANCE;
}

public void addPageMeta(PageMeta pageMeta) throws SAXException,
        WingException, SQLException, IOException,
        AuthorizeException {
    pageMeta.addMetadata("title").addContent(T_title);
    pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
    pageMeta.addTrail().addContent(T_trail);
}

public void addBody(Body body) throws SAXException, WingException,
        UIException, SQLException, IOException, AuthorizeException {
    // Build the item viewer division.
    Division ill = body.addInteractiveDivision("ill-form",
            contextPath + "/ill", Division.METHOD_POST, "primary");
    ill.setHead(T_head);
    ill.addPara(T_para1);
    List form = ill.addList("form", List.TYPE_FORM);
    Text email = form.addItem().addText("email");
    email.setAutofocus("autofocus");
    email.setLabel(T_email);
    email.setHelp(T_email_help);
    email.setValue(parameters.getParameter("email", ""));
    TextArea message = form.addItem().addTextArea("message");
    message.setLabel(T_message);
    message.setValue(parameters.getParameter("message", ""));
    CheckBox copyright = form.addItem().addCheckBox("accept");
    String selected = !parameters.getParameter("accept", "true").equalsIgnoreCase("false") ? "true" : "false";
    copyright.setOptionSelected(selected);
    copyright.addOption("accept", T_copyright_agree);
    copyright.setLabel(T_copyright_label);
    copyright.setHelp(T_copyright);
    form.addItem().addButton("submit").setValue(T_submit);
    ill.addHidden("page").setValue(parameters.getParameter("page", "unknown"));
}
}

在此先感谢您的帮助。

4

1 回答 1

0

您可以将定义复选框的 HTML 更改为如下所示:-

onClick="EnableSubmit(this)"

就像是:-

<input type="checkbox" name="ABC" value="XYZ" onClick="EnableSubmit(this)">
于 2013-08-11T06:38:40.277 回答