【发布时间】:2016-04-29 22:56:16
【问题描述】:
我收到语法错误:
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+")");
}
在子 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!")
});
}
【问题讨论】:
-
subject.subjectId是数字还是字符串? -
@RickHitchcock 这是一个字符串
-
这可能是问题所在。试试
onclick="changeDeleteId('${subject.subjectId}')" -
stackoverflow.com/questions/4506219/… 对这篇文章接受的答案的评论谈到像你一样传递参数
-
我按照那里的建议编辑了代码 $("#delete_no").attr("onclick","deleteSubjects('"+x+"')");但仍然遇到同样的问题。
标签: javascript jquery ajax jsp