jquery提交不提交

时间:2013-08-29 23:21:15

标签: javascript jquery

此脚本的对话框部分有效,但表单未提交

    $(document).ready(function(){
  $("form#audit_delete_form").submit(function(e) {
    e.preventDefault();
    var $form = $(this);
    if ($form.find('select[name="audit_id_select"]').val() == "") {
        $.msgbox("Please select an audit", {
        type:"alert",
        buttons: [
        {type: "submit", value: "OK"}
        ]
      });
    }else{
        $.msgbox("Are you sure you want to permanently delete this audit?", {   
        type: "confirm",
         buttons : [
            {type: "submit", value: "Yes"},
            {type: "submit", value: "No"},
            {type: "cancel", value: "Cancel"}
          ]
      }, function(result){
          if(result == 'Yes'){
              $(this).submit()
          }
      });

    }
  });
});

1 个答案:

答案 0 :(得分:0)

无论如何,请尝试使用e.preventDefault();。然后在用户确认时发出提交。

$(THE_SUBMIT_BUTTON_ID).click(function(e){
e.preventDefault();
if(...){...}
else{
        $.msgbox("Are you sure you want to permanently delete this audit?", {   
        type: "confirm",
         buttons : [
            {type: "submit", value: "Yes"},
            {type: "submit", value: "No"},
            {type: "cancel", value: "Cancel"}
          ]
      }, function(result){
          if(result == 'Yes'){
              $("form#audit_delete_form").submit() // We only submit when prompted
          }