2

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

    <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 的对话来修饰它。这些示例看起来很棒,但我没有看到如何在现有形式中使用它。我对 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 的 Confirmation 示例与上面的表单正确合并,我需要进行哪些更改?

4

1 回答 1

0

尝试这个:

<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>

希望这能回答你的问题。

于 2013-01-28T19:10:46.087 回答