为什么必须单击模式按钮两次才能发布到表单?

时间:2016-06-24 21:10:04

标签: jquery twitter-bootstrap

我有一个Bootstrap 3模式弹出,然后我必须单击两次删除按钮才能工作。我的其他模态不会这样做,但不确定我在jquery代码中做了什么导致这个?

<script>
$(document).ready(function(e){
//[delete] button
$('#delete_questions1').on('shown.bs.modal', function (e) {
    var btn = $(e.relatedTarget);
    var questionID = btn.data('mylink1');  //calls in bootstrap data-mylink1=\"$row[questionID]\"
    var auditID = btn.data('mylink2');  //calls in bootstrap data-mylink2=\"$row[auditID]\"

    $('#deletequestion').text(auditID);//links auditID to our input button
    $('#deletequestion').text(questionID);  //links questionID to our input button
    $('#deletequestion').click(function() {
        //alert("edit_questions.php?action=delete&questionID="+questionID+"&auditID="+auditID); //testing button
        $.post("edit_questions.php?action=delete&questionID="+questionID+"&auditID="+auditID, function(data) {
            if(data) {
                //alert(data);
                alert('You have successfully DELETED the quesiton for this audit.');
            window.location.reload(true);
            }
        });//End post 
    }); 

        var button_text=$(this).attr("value");
        if(button_text=="Restore"){
            var title1="Restore Question";
            var msg="You have selected to <strong>RESTORE</strong> this question. Are you sure thats what you want to do?";
        }else{
            var title1="Delete Question";
            var msg="Are you sure you want to <strong>DELETE</strong> this question? If the audit has NOT been published you will not be able to get it back.";
        }
            $('#DeleteQuestionTitle1').html(title1);
            $('#DeleteQuestionText1').html(msg);
    });//End Delete
}); //End Main JQuery Function      
</script>

要弹出模态的按钮:

                        <input 
                        data-mylink1=\"$row[questionID]\" 
                        data-mylink2=$auditID
                        type='button'
                        class='btn btn-danger btn-xs' role='button'                 
                        data-toggle='modal' 
                        data-target='#delete_questions1'
                        value=$edit_button />

弹出的Bootstrap 3模式 - 必须单击两次删除按钮才能工作

                  <!-- modal pop up for [delete] button-->
<div class="modal" id="delete_questions1"  style="z-index:10000" role="dialog" aria-labelledby="basicModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title" id="DeleteQuestionTitle1"></h4>
            </div>
            <div class="modal-body" id="DeleteQuestionText1">

            </div>
            <div class="modal-footer">
            <form role="form" method = "POST">

                <input class="btn btn-default"  type="button" id="deletequestion" value='Delete' />

                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>       
            </form> 
            </div>
        </div>
    </div>
</div>  

1 个答案:

答案 0 :(得分:0)

我评论了这一部分,因为它是多余的,现在只需点击一下就可以了!

//  if(data) {
                //alert(data);
//  }