我收到语法错误:
Uncaught Syntax Error: missing ) after argument list
表格中的数据似乎显示正常。当我点击表格中的删除按钮时出现错误。但我似乎无法找到代码的任何问题。
它的工作流程是当我点击删除按钮时,它会打开一个模型窗口,询问我是否确定要删除所选的条目,并且一旦我点击是,它应该删除它。但是,当我点击删除按钮时,我会弹出窗口,但是当我在窗口上按“是”时没有任何反应。代码被卡住了。
在主JSP中:
<div id="subjectArea">
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content my-popup">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
<span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Delete</h4>
</div>
<div class="modal-body"> Are You Sure to Delete? </div>
<div class="modal-footer">
<button type="button" class="btn btn-success" id="delete_no" onclick="">Yes</button> <button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<script>
function changeDeleteId(x) {
$("#delete_no").attr("onclick","deleteSubjects("+x+")");
}
在Sub JSP中:
<table width="100%" id="example" class="table table-bordered" cellspacing="0" style="font-size: 14px ; margin-left: 10px; text-align: center; border: 1px solid black;">
<%--Table Headers--%>
<th style="text-align: center">Sr.</th>
<th style="text-align: center">Code</th>
<th style="text-align: center">Title</th>
<th style="text-align: center">Status</th>
<th style="text-align: center">Actions</th>
</tr>
<c:forEach items="${subjects}" var="subject" varStatus="counter">
<tr style="align-items: center">
<td style="font-size: 14px ; border: 1px solid black; background-color: white">${counter.count}</td>
<td style="font-size: 14px ; border: 1px solid black; background-color: white">${subject.subjectCode}</td>
<td style="font-size: 14px ; border: 1px solid black; background-color: white">${subject.subjectName}</td>
<td style="font-size: 14px ; border: 1px solid black; background-color: white">${subject.status}</td>
<td style="font-size: 14px ; border: 1px solid black; background-color: white; text-align: center; margin-left: 20px">
<%--<a style="color: green; font-weight: bold" href="${pageContext.request.contextPath}/subject/edit/${subject.subjectId}">Edit</a> | --%>
<a style="text-align: center" href="${pageContext.request.contextPath}/subject/edit/${subject.subjectId}" title="Edit"><i class="fa fa-pencil-square-o edit"></i></a>
<a data-toggle="modal" data-target="#myModal" style="color: red; font-weight: bold" onclick="changeDeleteId(${subject.subjectId})"><i class="fa fa-trash-o delet"></i></a>
</td>
</tr>
</c:forEach>
JavaScript文件:
function deleteSubjects(x) {
var url = 'delete/' + x;
$.get(url, function(content) {
$("#subjectArea").html(content);
}).fail(function() {
alert("Something Went Wrong, Try Again!")
});
}
答案 0 :(得分:0)
您粘贴的代码有两个问题:
${subject.subjectId}
是一个字符串,它必须作为字符串传递给changeDeleteId
函数,即用引号changeDeleteId('${subject.subjectId}')
$("#delete_no").attr("onclick","deleteSubjects("+x+")");
不是将函数绑定到click事件的正确方法。请改用jQuery on()
。请参阅其API Doc并查看&#34下的示例;将数据传递给处理程序&#34;。
最后,您的代码将如下所示:
function changeDeleteId(subjectId) {
$("#delete_no").on("click", deleteSubjects, {subject: subjectId});
}
function deleteSubjects(event) {
var url = 'delete/' + event.data.subject;
}