【问题标题】:Capturing response with a JQuery modal dialogue使用 JQuery 模式对话捕获响应
【发布时间】:2013-01-12 05:03:52
【问题描述】:

我有一个简单的确认对话:

    <script type='text/javascript'>
        function confirmPubGL( theForm )
        {
            theForm.submit.disabled = true;
            var r=confirm('Are you sure you want to press the OK button?')
            if (r==true)
            {
                alert('Submitting form data now.');

            } else {
                alert('Nothing happened.')
                theForm.submit.disabled = false;
            }

        }
    </script>   

    <form name='abc' id='abc' method='post' action='feedme.php' onSubmit="return confirmPubGL(this)">
        <input type=hidden name=action  value='submitme'>
        <input type=submit name='submit' value='Click Me!'>
    </form>

我想使用 JQuery 的dialogues 来修饰它。这些示例看起来很棒,但我没有看到如何在现有形式中使用它。我对 JQuery 还很陌生,所以我可能忽略了一些非常容易的事情。

<script>
    $(function() {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Do it!": function() {
                    $( this ).dialog( "close" );
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
</script>


    <form name='abc' id='abc' method='post' action='feedme.php' onSubmit="return WhatDoIDoHere()">
        <input type=hidden name=action  value='submitme'>
        <input type=submit name='submit' value='Click Me!'>
    </form>

<div id='dialog-confirm' title='Submit Data?'>
<p><span class='ui-icon ui-icon-alert' style='float: left; margin: 0 7px 20px 0;'></span>You are about to submit data. Are you sure?</p>
</div>

为了将 JQuery 的确认示例与上述表单正确结合,我需要进行哪些更改?

【问题讨论】:

  • 确认对话框后是否显示 jQuery UI 对话框?
  • 您还在使用正常的表单提交操作吗?还是要改用ajax?
  • 这个表单我不需要 ajax。

标签: jquery dialog modal-dialog confirmation


【解决方案1】:

试试这个:

<script>
    $(function() {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Do it!": function() {
                    var confirmMsg = "Are you sure?";
                    if (confirm(confirmMsg)) {
                        // Send your form
                    } else {
                        $( this ).dialog( "close" );
                    }
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
</script>

更新:

对不起,我在后一个答案中的错误。我没听懂你的问题。

<script>
    function WhatDoIDoHere() {
        $("#dialog-confirm").dialog("open");
    }
</script>

希望这能回答你的问题。

【讨论】:

  • 如何从表单中调用 jquery 对话?在第一个示例中,从
    标记中的 onSubmit 调用旧的 confirm() 对话。
  • 您刚刚在替换确认对话框中添加了一个确认框...他想用对话框替换使用确认框
  • 很确定我还有其他问题。错误控制台未显示错误,但对话框无法正常工作。 jsfiddle.net/G8x2k/1
  • 我想选择您的答案,但不确定它是否有效。你能看看上面的小提琴吗?
  • 首先,你可以禁用写autoOpen: false的jQuery对话框的autoOpen属性。然后,我认为您的问题是,当您提交表单时,他们会重新加载页面。尝试使用 html 按钮打开对话框。
猜你喜欢
  • 2018-07-02
  • 1970-01-01
  • 2012-12-04
  • 2016-12-14
  • 1970-01-01
  • 2011-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多