1

当我从 href 标记中选择犯罪编号时,此页面会显示几条记录,我只想在该行中发布数据。有人可以告诉我我哪里出错了:我为从服务器返回的每条记录做了不同的表格,但只有第一条记录一直被返回。

编辑 该页面是使用 java 脚本发布的,其接收的 Id 为 NULL

CrimeRecNo 准确地张贴了但是受害者和犯罪名单只张贴了第一行而不是选定的那一行。为什么????

function submitPage(crimeRecNo) {

        document.getElementById("crimeList"+$('#crimeRecNo').val()).action = "getCrime/"+ crimeRecNo + ".htm";
        document.getElementById("crimeList"+$('#crimeRecNo').val()).method = "POST";
        document.getElementById("crimeList"+$('#crimeRecNo').val()).submit();

    }

html

  </head>
<body>
    <c:forEach items="${crimes}" var="crime">
        <form:form id="crimeList${crime.crimeRecNo}" name="crimeList" commandName="crime">
            <div id="content">

                <div class="row-${crime.crimeRecNo}">
                    <h2>                            
                        <a class="crimeRecNo" href="${crime.crimeRecNo}">Crime Record
                            Number : ${crime.crimeRecNo}</a><form:input path="crimeRecNo" id="crimeRecNo"
                                            value="${crime.crimeRecNo}" />

                    </h2>

                    <div class="crimeReport">
                        <label>${crime.crimeDetails}</label>
                    </div>

                    <div id="container">

                        <div id="crimePhotoz">
                            <div id="victimLabel">
                                <label class="heading">Victims/Witness In Crime</label>
                            </div>
                            <div class="grid_row">

                                <c:forEach items="${crime.victims}" var="victim">
                                    <input type="hidden" value="${victim.photo}" class="foto" />
                                    <canvas class="canvas" height="200" width="200"></canvas>
                                </c:forEach>

                                <c:forEach items="${crime.victims}" var="victim">
                                    <div class="names">
                                        <a class="crimeNames" href="${victim.socialSecurityNumber}">${victim.name}</a>
                                        <form:input path="victims" id="victims" value="${victim.socialSecurityNumber}" />
                                    </div>
                                </c:forEach>

                            </div>

                            <div id="criminalLabel">
                                <label class="heading">Criminals In Crime</label>
                            </div>
                            <div class="grid_row2">

                                <c:forEach items="${crime.criminals}" var="criminal">
                                    <input type="hidden" value="${criminal.photo}" class="foto" />
                                    <canvas class="canvas" height="200" width="200"></canvas>
                                </c:forEach>

                                <c:forEach items="${crime.criminals}" var="criminal">
                                    <div class="names">
                                        <a class="crimeNames" href="${criminal.socialSecurityNumber}">${criminal.name}</a>
                                        <form:input path="criminals" id="criminals" value="${criminal.socialSecurityNumber}" />
                                    </div>
                                </c:forEach>
                            </div>
                        </div>
                    </div>
                </div>
                <hr>
            </div>
        </form:form>
    </c:forEach>


</body>
</html>
4

1 回答 1

2

也许你错过了一些报价?

document.getElementById(${crime.crimeRecNo})

如果${crime.crimeRecNo}是一个字符串,这就变成

document.getElementById(myRecNo)

这是无效的javascript。在这种情况下,您应该添加引号:

document.getElementById("${crime.crimeRecNo}")

如果${crime.crimeRecNo}是一个数字,您不需要引号,但您可能有无效的 ID。根据这个html ids 必须至少以一个字符开头。我不确定这是否会导致问题,但也许你应该尝试<form id="record-${crime.crimeRecNo}" .. >

于 2013-04-20T19:02:47.080 回答