Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果浏览器中禁用了javascript,如何在表单提交时弹出javascript并执行操作?_Javascript_Jquery_Forms_Popup - Fatal编程技术网

如果浏览器中禁用了javascript,如何在表单提交时弹出javascript并执行操作?

如果浏览器中禁用了javascript,如何在表单提交时弹出javascript并执行操作?,javascript,jquery,forms,popup,Javascript,Jquery,Forms,Popup,我有以下重定向到确认页面的表单,当浏览器中禁用javascript时,我希望保持这种行为,但是当启用javascript时,我希望使用弹出窗口进行确认。 当启用javascript只显示确认弹出窗口时,如何禁用表单操作? ps:我必须使用jQueryUILightness插件,这就是为什么我不使用引导模式 <head> <meta charset="UTF-8"> <meta name="viewport" c

我有以下重定向到确认页面的表单,当浏览器中禁用javascript时,我希望保持这种行为,但是当启用javascript时,我希望使用弹出窗口进行确认。 当启用javascript只显示确认弹出窗口时,如何禁用表单操作? ps:我必须使用jQueryUILightness插件,这就是为什么我不使用引导模式

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="lib/jquery-ui-1.12.1.ui-lightness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="lib/jquery-ui-1.12.1.ui-lightness/jquery-ui.theme.min.css" rel="stylesheet" type="text/css" />
    <link href="lib/jquery-ui-1.12.1.ui-lightness/jquery-ui.structure.min.css" rel="stylesheet" type="text/css" />
    <script src="lib/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script src="lib/jquery-ui-1.12.1.ui-lightness/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
    <script>
        $("#btn_trash").click(function() {
            var ret = null;
            $('#confirmDialog').dialog({
                resizable: false,
                height: 300,
                width: 500,
                modal: true,
                autoOpen: true,
                buttons: {
                    Oui: function() {
                        ret = "yes";
                        $(this).dialog("close");
                    },
                    Non: function() {
                        ret = "no";
                        $(this).dialog("close");
                    }
                },
                close: function() {
                    if (ret !== null)
                        $("#content").html("You answered <b>" + ret + "</b>.");
                    else
                        $("#content").html("You didn't answer.");
                }
            });
        });
    </script>


    <form id="delete_board_form" action='board/submit_delete' method='post'>
        <input type='text' name='delete' value='<?= $board->id ?>' hidden>
        <button id="btn_trash" class="btn" type="Submit">
          <svg class="bi text-white" width="20" height="20">
            <use xlink:href="assets/ressources/bootstrap-icons/bootstrap-icons.svg#trash" />
          </svg>
        </button>
    </form>
    <div id="content"></div>
    <div id="confirmDialog" title="Attention" hidden>
        <p>Confirmez-vous le lancement de cette opération irréversible ?</p>
    </div>

</body>

文件
$(“#btn_垃圾”)。单击(函数(){
var-ret=null;
$('confirmDialog')。对话框({
可调整大小:false,
身高:300,
宽度:500,
莫代尔:是的,
自动打开:对,
按钮:{
Oui:function(){
ret=“是”;
$(此).dialog(“关闭”);
},
非:函数(){
ret=“否”;
$(此).dialog(“关闭”);
}
},
关闭:函数(){
如果(ret!==null)
$(“#content”).html(“您回答了”+ret+”);
其他的
$(“#内容”).html(“您没有回答。”);
}
});
});

对我有效的是使用event.preventDefault()



您的问题归结为“如何使用JavaScript防止表单提交”,这很容易研究。@CBroe谢谢您的帮助,我没有用这些术语搜索。你是对的,在研究了你的术语之后,很快就找到了答案!
<form id="delete_board_form" action='board/submit_delete' method='post' onsubmit="event.preventDefault()">
        <input type='text' name='delete' value='<?= $board->id ?>' hidden>
        <button id="btn_trash" class="btn" type="Submit">
          <svg class="bi text-white" width="20" height="20">
            <use xlink:href="assets/ressources/bootstrap-icons/bootstrap-icons.svg#trash" />
          </svg>
        </button>
    </form>
    <div id="content"></div>
    <div id="confirmDialog" title="Attention" hidden>
        <p>Confirmez-vous le lancement de cette opération irréversible ?</p>
    </div>
    ````