0

我有这样的表格:

<form action="confirm-and-send.php" method="post" onsubmit="return(confirmation());">
    <input a lot of input fields here>
    <button type="submit" name="confirm_and_send" id="submit-button"  class="sent-to-client-bttn" style="margin-left:630px;margin-top: -125px;"></button>
</form> 

然后我有 jquery ui 功能

function confirmation(){
   $("#some-div").dialog({
        bgiframe: true,
        autoOpen: false,
        minHeight: 200,
        width: 350,
        modal: true,
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        buttons: {
                'Yes': function(){
                    $(this).dialog('close');
                    callback(true);
                },
                'No': function(){
                    $(this).dialog('close');
                    callback(false);
                }
            }
    });
}
function callback(value){
     //do something
}

我正在关注他们在这里这里所说的话,但这对我不起作用。如果我把event.preventDefault()是按钮将不会提交;如果我不把它提交表格,然后我选择两个选项中的任何一个。任何人都可以给我一个合适的例子吗?

4

2 回答 2

0

我认为您正在使用 JqueryUi 对话框..它不起作用..为此您必须使用

我向你解释当你点击..时会发生什么

它不会因为你的点击而停止..它会自动提交......所以你必须尝试默认..浏览器确认

于 2013-09-04T07:08:16.880 回答
0

将您的按钮放在表单之外。

<form action="" method="post" id="my_form" onsubmit="">
        <input type="text" name="x"/>

    </form> 
    <button name="confirm_and_send" id="submit-button" value="Submit" class="sent-to-client-bttn" onclick="confirmation();">Submit</button>
    <div id="some-div" style="display:none">Hi</div>


function confirmation(){


   $("#some-div").dialog({
        bgiframe: true,
        minHeight: 200,
        width: 350,
        modal: true,
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        buttons: {
                'Yes': function(){
                    $(this).dialog('close');
                    callback(true);
                },
                'No': function(){
                    $(this).dialog('close');
                    callback(false);
                }
            }
    });


}
function callback(value){
     alert(value);
}
于 2013-09-04T07:11:02.900 回答