gpt4 book ai didi

javascript - jquery preventDefault on alert,如果 alert = ok,则发送

转载 作者:行者123 更新时间:2023-11-30 16:27:03 29 4
gpt4 key购买 nike

我正在尝试创建一个警报,以确保用户提交了正确的信息,如果单击“确定”而不是取消,则单击链接并 <a>发送。我几乎已经实现了,警报激活,但如果单击确定则不会激活。不幸的是,我还不是 js 向导......

编辑:

click => preventDefault => alert (yes, no) if yes(send) if no dont.

<script>
jQuery(document).ready(function($){

$("input.btn-default").click(function(e){
e.preventDefault();
var answer=confirm('Are you sure that you want to do this?');
if(answer == true){
///not sure how to remove the prevent default and send link?!
}
else{
return;
}
});
});

</script>

最佳答案

如果用户取消确认对话框并使用 window.open( $(this).att('href') ); 来尝试以下代码,则使用 return false;当用户单击“确定”时打开链接:

$("input.btn-default").click(function(e)
{
e.preventDefault();

if( confirm('Are you sure that you want to do this?') )
{
window.open( $(this).att('href') );
}
else
{
return false;
}
});

希望这对您有所帮助。

关于javascript - jquery preventDefault on alert,如果 alert = ok,则发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33962389/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com