gpt4 book ai didi

javascript - 使用未提交的表单关闭页面时询问确认

转载 作者:行者123 更新时间:2023-11-29 17:09:22 25 4
gpt4 key购买 nike

<分区>

我有一个表单,我想在提交值之前询问用户关闭页面时的确认。我已经尝试过 this question 中描述的脚本但它似乎不起作用:userSubmitted 值数字始终为真,并且不会出现弹出窗口。

我模板中的代码是:

 <script>
window.onbeforeunload = function() {
if(!userSubmitted)
return 'Are you sure that you want to leave this page?';};
</script>

我的 Controller 中的代码是:

$userSubmitted=false;
//...

$form->handleRequest($request);
if ($form->isValid()) {
$userSubmitted=true;

//...
return $this->render('DefaultBundle::formupload.html.twig', array(
'form' => $form->createView(), 'userSubmitted->$userSubmitted
));
//...

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