我必须在我的表单中使用动态 id,基于 scriptlet 中的 jsp 变量。如何使用 jQuery 的 id 选择器选择正确的元素而不会出错?
这是我的代码:
<form name="intakeOnly" id="intakeOnly_<%=complaint%>" method="post" action="../Intake.do">
<table class="normal">
<tr>
<td><b>Clinician Signature: </b> <span id="cSigI_<%=complaint%>"><%=clinicianSig%>,<%=signedDate%></span></td>
</tr>
<tr>
<td><input type="button" id="submitSig_<%=complaint%>" name="submitSig" value="Sign and Save" onClick="intakeSubmit();"></td>
</tr>
</table>
</form>
Javascript:
function intakeSubmit() {
var complaint = <%=complaint%>;
var fname = new String("<%=userFirstName%>");
var lname = new String("<%=userLastName%>");
var date = new String("<%=DateUtils.getDate()%>");
jQuery("#cSigI_"+complaint).append("<br>"+fname+" "+lname + ","+ date);
}