Javascript sj:提交目标属性不适用于ajax表单

Javascript sj:提交目标属性不适用于ajax表单,javascript,jquery,ajax,struts2,struts2-jquery,Javascript,Jquery,Ajax,Struts2,Struts2 Jquery,我的ajax生成表单的targets属性似乎不起作用。我似乎也无法发布此表单中的主题。我有以下一页: <!Doctype html, taglibs, etc here !--> <html> <head> <s:head theme="css_xhtml" /> <sj:head jqueryui="true" /> <script type="text/javascript">

我的ajax生成表单的targets属性似乎不起作用。我似乎也无法发布此表单中的主题。我有以下一页:

<!Doctype html, taglibs, etc here !-->
    <html>
    <head>
    <s:head theme="css_xhtml" />
    <sj:head jqueryui="true" />
    <script type="text/javascript">
        $.subscribe('testtopic', function(event, data) {
            alert('testtopic Published!');
        });
    </script>
    <title>Exam CRUD</title>
    </head>
    <s:url namespace="/exam" action="ReadAll" var="readExamsTag" />
    <body>
        <s:include value="/WEB-INF/content/navigation.jsp" />
        <h2>Exam CRUD</h2>
        <sj:div id="formcontainer"></sj:div>
        <sj:div id="tablecontainer" loadingText="Loading.."
            reloadTopics="reloadTable" href="%{readExamsTag}">
        </sj:div>
    </body>
    </html>

$.subscribe('testtopic',函数(事件、数据){
警报('testtopic Published!');
});
检查积垢
检查积垢
ReadAll将以下jsp加载到“tablecontainer”div中:



下面列出了目前学生可以参加的考试。
增加考试

%{createFormTag}单击正在加载到“formcontainer”中的表单:

<sj:head />

<s:form  theme="css_xhtml" namespace="/exam" action="Create">
    <!Form fields>
    <input type="button" value="Cancel" onclick="$('#formcontainer').empty();">
    <sj:submit targets="formcontainer" onCompleteTopics="reloadTable" value="Add" />
</s:form>

<sj:a href="#" onClickTopics="testtopic">Test</sj:a>

试验
我面临的问题来自上面的表格。“目标”属性不起作用,提交此表单时会将结果加载到新页面。我还想测试主题是否可以发布,所以我在表单末尾添加了锚。当表单加载到页面中时,单击此锚定不会执行任何操作。“Cancel”(取消)按钮似乎工作正常,加载此表单的初始锚点也工作正常,那么为什么表单不工作呢

编辑:修正了

我不知道为什么会这样,肯定与css_xhtml模板有关。我通过在表单中添加id属性修复了targets属性

至于修复发布,我在表单中的datepicker字段中添加了一个id属性,现在一切都正常了。奇怪的 最终代码: crud.jsp:

 <!DOCTYPE html>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <html>
    <head>
    <s:head theme="css_xhtml" />
    <sj:head jqueryui="true"/>
    <title>Exam CRUD</title>
    </head>
    <s:url namespace="/exam" action="ReadAll" var="readExamsTag" />
    <body>
        <s:include value="/WEB-INF/content/navigation.jsp" />
        <h2>Exam CRUD</h2>
        <sj:div id="formcontainer"></sj:div>
        <sj:div id="tablecontainer" loadingText="Loading.."
            reloadTopics="reloadTable" href="%{readExamsTag}">
        </sj:div>
    </body>
    </html>

检查积垢
检查积垢
add.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>

<s:form id="addform" theme="css_xhtml" namespace="/exam" action="Create">
    <s:textfield name="exam.name" label="Name" required="true" />
    <s:textfield name="exam.author" label="Author" />
    <s:textfield name="exam.minutesAllotted" label="Time limit"
        required="true" />
    <sj:datepicker id="startingDate" name="exam.startingDate"
        label="Start date" timepicker="true" readonly="true"
        displayFormat="dd/mm/yy" changeMonth="true" changeYear="true"
        minDate="-0d" maxDate="+2y" />
    <sj:datepicker id="endingDate" name="exam.endingDate" label="End date"
        timepicker="true" displayFormat="dd/mm/yy" changeMonth="true"
        changeYear="true" readonly="true" minDate="-0d" maxDate="+2y" />

    <input type="button" value="Cancel"
        onclick="$('#formcontainer').empty();">
    <sj:submit targets="formcontainer" value="Add" />
</s:form>


我不需要在第二个jsp中更改任何内容

仅包括一次Aleksandr M

仅包含一次
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>

<s:form id="addform" theme="css_xhtml" namespace="/exam" action="Create">
    <s:textfield name="exam.name" label="Name" required="true" />
    <s:textfield name="exam.author" label="Author" />
    <s:textfield name="exam.minutesAllotted" label="Time limit"
        required="true" />
    <sj:datepicker id="startingDate" name="exam.startingDate"
        label="Start date" timepicker="true" readonly="true"
        displayFormat="dd/mm/yy" changeMonth="true" changeYear="true"
        minDate="-0d" maxDate="+2y" />
    <sj:datepicker id="endingDate" name="exam.endingDate" label="End date"
        timepicker="true" displayFormat="dd/mm/yy" changeMonth="true"
        changeYear="true" readonly="true" minDate="-0d" maxDate="+2y" />

    <input type="button" value="Cancel"
        onclick="$('#formcontainer').empty();">
    <sj:submit targets="formcontainer" value="Add" />
</s:form>