【问题标题】:Adding submit button value to submit()将提交按钮值添加到 submit()
【发布时间】:2011-05-02 14:28:38
【问题描述】:

我在删除记录时使用 Jquery UI 对话框作为确认。我想要实现的是,当您单击值为“删除”的提交按钮时,它将打开对话框窗口并确认您的选择。如果您选择是,它将使用提交按钮的值提交表单。我知道它目前不起作用,因为 submit() 无法知道单击了哪个按钮,但我不知道该怎么做?非常感谢。

<script type="text/javascript">
$(document).ready(function(){
    $("#dialog").dialog({
      modal: true,
            bgiframe: true,
            width: 500,
            height: 200,
      autoOpen: false
      });

    $("#rusure").click(function(e) {
        e.preventDefault();
        $("#dialog").dialog('option', 'buttons', {
                "Confirm" : function() {
                    $("#tasks").submit();
                    },
                "Cancel" : function() {
                    $(this).dialog("close");
                    }
                });
        $("#dialog").dialog("open");
    });
});
</script>
<input type="submit" name="action" value="Delete" id="rusure"/>

表单称为“tasks”,包含对话框内容的隐藏 div 称为“dialog”。目前,除了使用提交按钮的值提交的表单之外,一切都运行良好。表单中还有 2 个提交按钮。

【问题讨论】:

    标签: javascript jquery ajax jquery-ui


    【解决方案1】:

    试试这个:

    $("#rusure").click(function(e) {
    
        e.preventDefault();
    
        // Create hidden input from button and append to form
        var input = $('<input name="confirm_delete" value="yesplz" type="hidden" />').appendTo('#tasks');
    
        $("#dialog").dialog('option', 'buttons', {
                "Confirm" : function() {
                    $("#tasks").submit();
                    },
                "Cancel" : function() {
                    $(this).dialog("close");
                    $(input).remove();// Remove hidden input
                    }
                });
    
        $("#dialog").dialog("open");
    
    });
    

    在这里演示:http://jsfiddle.net/Madmartigan/ZGLNc/1/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-08
      • 2021-05-27
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      相关资源
      最近更新 更多