[英]Javascript confirm Stop page refresh after cancel
I have made a JavaScript function which is attached to the cancel button on of a form.我制作了一个 JavaScript 函数,它附加到表单的取消按钮上。 The issue I am finding is that when the cancel button is pressed the page/form reloads losing the data in the text fields.我发现的问题是,当按下取消按钮时,页面/表单重新加载会丢失文本字段中的数据。
function cancelConfirm(){
var confirmCancel = confirm("Are you sure you wish to cancel?");
if(confirmCancel==true)
{
alert("byebye");
}
else
{
return false;
}
};
I was just wondering how can you prevent the page from reloading after the cancel button on the confirm has been clicked?我只是想知道在单击确认上的取消按钮后如何防止页面重新加载? Thanks for any help you can give谢谢你提供的所有帮助
function cancelConfirm() {
var confirmCancel = confirm("Are you sure you wish to cancel?");
if (confirmCancel == true) {
alert("byebye");
return false;// to stop postback on ok cick of confirmation popup
}
else {
return false;
}
}
你可以用一个简单的方法
<a href="" onclick="return confirm('Are you sure!!!!')">Delete </a>
What you can do is to add an onClick event and pass the event object down to it.您可以做的是添加一个 onClick 事件并将事件对象传递给它。
{onClick(e) => {
e.preventDefault();
//do something here
}}
A simple e.preventDefault()
is what you need.一个简单的e.preventDefault()
就是你所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.