我需要发出一条警报消息来确认是否要删除所选数据。到目前为止,我能够生成警报消息。但是是否可以在警报消息中添加数据?因为我尝试将数据添加到警报中,但将数据传递给警报功能时警报不起作用。
<c:forEach items="${instituteList}" var="instituteList">
<tr class="odd gradeX">
<td>${instituteList.instituteName}</td>
<td><a href="#" onclick=deleteAlert(${instituteList.instituteName},${instituteList.id})><button type="button" class="btn btn-danger btn-xs" >Delete</button></a></td>
</tr>
</c:forEach>
<script>
function deleteAlert(String name, String id) {
var confirmmessage = "Are you sure you want to Delete"+name+"?";
var go = "deleteInstitute?id="+id;
var message = "Action Was Cancelled By User";
if (confirm(confirmmessage)) {
window.location = go;
} else {
alert(message);
}
}
</script>
如果我不通过警报函数传递任何值,则会弹出警报,但如果我传递任何值,则不会发生任何情况。
最佳答案
试试这个
onclick="deleteAlert('${instituteList.instituteName}','${instituteList.id}')"
您在参数值周围缺少单引号,因此当 EL 解析时,您最终会得到类似 onclick="deleteAlert(My Institute, 10)"
的结果,这不好。
此外,@Hacketo 在评论中所说的,在 javascript 中,你的函数签名应该是 function deleteAlert(name, id)
。
关于javascript - 无法将值传递给 jsp 中的警报函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27604353/