javascript - 如何让确认框与 jsp 一起使用?
问题描述
所以每次我想从数据库中删除一条记录时,我想显示一个确认框,该框显示成功,但问题是无论我单击“确定”还是“取消”,记录都在删除
如何让它工作?谢谢
这是我的代码:
<table>
<thead>
<tr>
<th>ID</th>
<th>Date RDV</th>
<th>Motif</th>
<th>ID Patient</th>
<th>Action</th>
</tr>
</thead>
<p:forEach items="${liste }" var = "rdv">
<tbody>
<tr>
<td>${rdv.id_Rdv }</td>
<td>${rdv.date_Rdv }</td>
<td>${rdv.motif }</td>
<td>${rdv.id_P }</td>
<td>
<a href="${pageContext.request.contextPath}/RDVController?action=supprimer&Id_Rdv=${rdv.id_Rdv }" onclick="confirmation()" > Supprimer</a>
</td>
</tr>
</tbody>
</p:forEach>
</table>
这是我的javascript代码:
function confirmation(){
var result = confirm("vous êtes sûr ?");
if(result){
return true;
}
else{
return false;
}
}
解决方案
您可以使用button
而不是a
标签并应用于css
按钮,使其看起来像a
标签。在这里,在下面的代码中,每当您单击button
弹出窗口时,如果单击是,则会直接打开页面,否则页面将保持在同一页面上。
function confirmation(button) {
//getting href value
var href = button.getAttribute("href");
console.log(href);
var result = confirm("vous êtes sûr ?");
if (result) {
//if click yes redirect
window.location.href = href;
} else {
return false;
}
}
.supprimer {
background-color: transparent;
text-decoration: underline;
border: none;
color: blue;
cursor: pointer;
}
supprimer:focus {
outline: none;
}
<table>
<thead>
<tr>
<th>ID</th>
<th>Date RDV</th>
<th>Motif</th>
<th>ID Patient</th>
<th>Action</th>
</tr>
</thead>
<p:forEach items="${liste }" var="rdv">
<tbody>
<tr>
<td>${rdv.id_Rdv }</td>
<td>${rdv.date_Rdv }</td>
<td>${rdv.motif }</td>
<td>${rdv.id_P }</td>
<td>
<button class="supprimer" href="${pageContext.request.contextPath}/RDVController?action=supprimer&Id_Rdv=${rdv.id_Rdv }" onclick="confirmation(this)"> Supprimer</button>
</td>
</tr>
</tbody>
</p:forEach>
</table>
推荐阅读
- php - 警告:require_once():打开流失败:没有这样的文件或目录
- firebase - FIrestore 数据模型和密码功能的安全规则
- javascript - Canvas js如何将数据从数据库推送到Yii2中的图表
- php - 试图在同一行中选择不同的和计数,它是一半的工作?
- javascript - 其他
在 Jquery 中使用动态元素的方法,在删除和添加特定元素时不会导致空行。(由我解决) - coq - 如何证明排序列表
- html - css 绝对定位元素与其溢出父元素重叠
- python - 在同情中将因素置于激进之下
- python - 从服务中读取 XML - 为什么 XML 会自动转换为 JSON
- javascript - 尝试访问 Console.Log 中的数据