gpt4 book ai didi

javascript - 如何在收到警报后取消表单的操作?

转载 作者:太空宇宙 更新时间:2023-11-04 10:58:01 25 4
gpt4 key购买 nike

当用户提交表单时,writeToStorage 被触发并检查用户是否在 localStorage 中,如果是,则运行警报。在此警报之后,我不希望执行该操作。我试过 return false; 但显然这不会阻止 python 脚本运行。如果触发警报,如何停止表单的操作?

function writeToStorage() { 
var chooser = localStorage.getItem("chooser");
if (chooser) {
alert("you are already a user);
//return false; }
else {
//the rest of the program } };

# if alert is run the action of the form should not run
<form name="choice_form" id="choice_form" action="/g/choicehandler" method="post" onsubmit="writeToStorage()">
<textarea name="choice" rows="7" cols="50"></textarea><br />
<input type="hidden" name="chooser" id="form_chooser" />
<input type="submit" value="submit your choice">
</form>

最佳答案

添加你的return false 并改变:

onsubmit="writeToStorage()"

收件人:

onsubmit="return writeToStorage();"

关于javascript - 如何在收到警报后取消表单的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130380/

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