当用户提交表单时,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();"
我是一名优秀的程序员,十分优秀!