我想要得到一个确认消息点击删除(这可能是一个按钮或图像)。如果用户选择“Ok”,那么删除就完成了,否则如果点击“Cancel”,什么都不会发生。
当点击按钮时,我尝试回显这个,但是回显的东西使我的输入框和文本框失去了它们的样式和设计。
我想要得到一个确认消息点击删除(这可能是一个按钮或图像)。如果用户选择“Ok”,那么删除就完成了,否则如果点击“Cancel”,什么都不会发生。
当点击按钮时,我尝试回显这个,但是回显的东西使我的输入框和文本框失去了它们的样式和设计。
当前回答
试试这个。这对我很有用
<a href="delete_methode_link" onclick="return confirm('Are you sure you want to Remove?');">Remove</a>
其他回答
它可以简化为:
<button onclick="return confirm('Are you sure you want to delete?');" />
使用jQuery:
$(".delete-link").on("click", null, function(){
return confirm("Are you sure?");
});
<SCRIPT LANGUAGE="javascript">
function Del()
{
var r=confirm("Are you sure?")
if(r==true){return href;}else{return false;}
}
</SCRIPT>
你的链接:
<a href='edit_post.php?id=$myrow[id]'> Delete</a>
这就是使用不引人注目的JavaScript和在HTML中保存确认消息的方式。
<a href="/delete" class="delete" data-confirm="Are you sure to delete this item?">Delete</a>
这是一个纯香草JS,兼容IE 9+:
var deleteLinks = document.querySelectorAll('.delete');
for (var i = 0; i < deleteLinks.length; i++) {
deleteLinks[i].addEventListener('click', function(event) {
event.preventDefault();
var choice = confirm(this.getAttribute('data-confirm'));
if (choice) {
window.location.href = this.getAttribute('href');
}
});
}
看到它的行动:http://codepen.io/anon/pen/NqdKZq
它非常简单,只有一行代码
<a href="#" title="delete" class="delete" onclick="return confirm('Are you sure you want to delete this item')">Delete</a>