2016-07-11 3 views
0

저는 부트 스트랩이 새롭고 메시지 확인을위한 코드를 작성했습니다.확인 메시지에 부트 스트랩 사용 onclick()

다음 코드를 사용하여 onclick()을 어떻게 넣을 수 있습니까? bootbox의

$("#myModal").on("show", function() { // wire up the OK button to dismiss the modal when shown 
    $("#myModal a.btn").on("click", function(e) { 
     console.log("button pressed"); // just as an example... 
     $("#myModal").modal('hide');  // dismiss the dialog 
    }); 
}); 
$("#myModal").on("hide", function() { // remove the event listeners when the dialog is dismissed 
    $("#myModal a.btn").off("click"); 
}); 

$("#myModal").on("hidden", function() { // remove the actual elements from the DOM when fully hidden 
    $("#myModal").remove(); 
}); 

$("#myModal").modal({     // wire up the actual modal functionality and show the dialog 
    "backdrop" : "static", 
    "keyboard" : true, 
    "show"  : true      // ensure the modal is shown immediately 
}); 

는 HTML : onclick을

HTML (image)

() 입력 :

<input type='submit' name='actualiza_noticia' class='button' onClick="" value='Atualizar notícia'>  
+0

대신 이미지 –

+0

당신이 그것을가 표시된 후에, 일단 DOM에서 모달을 제거 하시겠습니까의 코드에서 HTML 코드를 추가 참조하십시오? 즉, 다시 표시 할 수 없으므로 대개 숨기기 만하면됩니다. –

+0

닫기 단추에 대한 html에는'data-dismiss = "modal"'이 있으므로 닫기 단추에 이벤트 리스너가 필요 없습니다. –

답변

1

당신은 하나를 사용하고 JQuery와 기능 $(elem).modal('show') 기능을 사용하거나 부트 스트랩 HTML 데이터 속성 수 있습니다 :

데이터 사용 attrib 백인 군대 :

<input type='submit' data-toggle="modal" data-target="#myModal" name='actualiza_noticia' class='button' value='Atualizar notícia' >  

JQuery와 기능 사용 :

<input onclick="$('#myModal').modal('show')" type='submit' name='actualiza_noticia' class='button' value='Atualizar notícia' >  

은이 두 이벤트를 트리거 shuold을의 'show' 이벤트가 'shown.bs.modal'가 부트 스트랩 3을 준수 수 있지만 자세한

$("#myModal").on('shown.bs.modal', function() { // wire up the OK button to dismiss the modal when shown 
    $("#myModal a.btn").on("click", function(e) { 
     console.log("button pressed"); // just as an example... 
     $("#myModal").modal('hide');  // dismiss the dialog 
    }); 
}); 

읽기 부트 스트랩 모달에 대해서 here.

+0

그것은 효과가 있었지만 지금은 또 다른 문제가 있습니까? 그것은 내 양식의 제출 작업을 취소하는 것 같습니다 ... 설명하는 것이 더 좋습니까? – Eddy

+0

나는 updtade delete 버튼을 사용하여 lits o 데이터를 출력하고 submite 후에는 checklogin.php 영역에서 choosed 업데이트 또는 삭제 여부를 확인하기 위해 잠시 동안 사용했다. bootbox를 사용하면 부팅했거나 표시하거나 숨 깁니다. – Eddy

0

내 제안이 당신의 HTML을보고 이미지에 따르면 ("shown.bs.modal"함수() { 에 $ ("#의 myModal")`에

  • 변화 $("#myModal").on("show", function() {. $("#myModal a.btn").on("click", function(e) {$("#myModal button.btn.btn-primary").off("click");
- $("#myModal").on("hide", function() { 변화 $("#myModal a.btn").off("click");
  • $("#myModal").on("hide.bs.modal", function() {로 변경
  • $("#myModal button.button.btn.btn-primary").on("click", function(e) {로 변경
  • 세부 bootstrap modals

    $(function() { 
     
          $("#myModal").on("shown.bs.modal", function() { // wire up the OK button to dismiss the modal when shown 
     
           $("#myModal button.btn.btn-primary").on("click", function(e) { 
     
            console.log("button pressed"); // just as an example... 
     
            $("#myModal").modal('hide');  // dismiss the dialog 
     
           }); 
     
          }); 
     
          $("#myModal").on("hide.bs.modal", function() { // remove the event listeners when the dialog is dismissed 
     
           $("#myModal button.btn.btn-primary").off("click"); 
     
          }); 
     
    
     
          $("#myModal").on("hidden", function() { // remove the actual elements from the DOM when fully hidden 
     
           $("#myModal").remove(); 
     
          }); 
     
    
     
          $("#myModal").modal({     // wire up the actual modal functionality and show the dialog 
     
           "backdrop" : "static", 
     
           "keyboard" : true, 
     
           "show"  : true      // ensure the modal is shown immediately 
     
          }); 
     
         });
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
     
    <script src="https://code.jquery.com/jquery-1.12.1.min.js"></script> 
     
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
     
    
     
    <div id="myModal" class="modal fade"> 
     
        <div class="modal-dialog"> 
     
         <div class="modal-content"> 
     
          <!-- dialog box --> 
     
          <div class="modal-body"> 
     
           <button type="btn btn-default" class="close" data-dismiss="modal">&times;</button> 
     
           Hello world! 
     
          </div> 
     
          <!-- dialog buttons --> 
     
          <div class="modal-footer"> 
     
           <button type="btn btn-default" class="btn btn-primary">OK</button> 
     
          </div> 
     
         </div> 
     
        </div> 
     
    </div>

  • +0

    효과가 있었지만 지금 또 다른 문제가 있습니까? 그것은 내 양식의 제출 작업을 취소하는 것 ... 더 나은 설명 나는 잠깐 동안 updtade 삭제 버튼과 submited 후 checklogin.php 영역에 choosed 업데이트 또는 삭제되었는지 확인하기 위해 lits o 데이터를 인쇄하는 데 사용 ... 그것은 작동하지만 부트 박스로, 그냥 보여 주거나 숨 깁니다. – Eddy

    관련 문제