0

我無法讓我的模式打開。我嘗試了Bootstrap 4網站上找到的純HTML,然後使用了一些Javascript。我真的無法弄清楚我做錯了什麼。任何幫助將非常感謝!Bootstrap 4 Modal將無法打開點擊

enter code here <

<div class="col-sm-3 col-centered boxes" id="box1"> 

    <button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal"> 

    See More 

    </button> 

    <!-- Modal --> 
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 

    <div class="modal-dialog" role="document"> 

     <div class="modal-content"> 

     <div class="modal-header"> 

      <h5 class="modal-title" id="exampleModalLabel">Wedding Invites</h5> 

      <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 

      <span aria-hidden="true">&times;</span> 

      </button> 

     </div> 

     <div class="modal-body"> 

      <img src="Wedding%20Invites.jpg"> 


     </div> 

     <div class="modal-footer"> 

      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 

      <button type="button" class="btn btn-primary">Save changes</button> 

     </div> 

     </div> 

    </div> 

    </div> 

</div> 
`enter code here`<script type="text/javascript"> 

enter code here $( 「#box1modal」)點擊(函數(事件){
enter code here $( '#myModal')模態( '秀'); enter code here )};

回答

1

如果您正在使用引導不需要額外scripting.bootstrap本身提供的腳本運行不同的動畫和行動的。我檢查你的代碼。 錯誤在於行

<button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal"> 

看到您已將數據目標設置爲#exampleModal,而您的模式的ID爲「myModal」。只需將上面的代碼更改爲

<button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#myModal"> 

而且在沒有任何其他腳本的情況下它將正常工作。 希望這有助於...

+0

非常感謝。這工作!我不敢相信我花了那麼多時間去想出來! – cerawebdesign

0

我測試你的代碼,每一個細微的東西只是你必須確保

1)添加引用 2)你的代碼必須是在$(文件)。就緒(函數(){} ----

<html> 
<head> 

<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<!-- jQuery library --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 

<!-- Latest compiled JavaScript --> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
</head> 

<body> 
<div class="col-sm-3 col-centered boxes" id="box1"> 

    <button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal"> 

    See More 

    </button> 

    <!-- Modal --> 
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 

    <div class="modal-dialog" role="document"> 

     <div class="modal-content"> 

     <div class="modal-header"> 

      <h5 class="modal-title" id="exampleModalLabel">Wedding Invites</h5> 

      <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 

      <span aria-hidden="true">&times;</span> 

      </button> 

     </div> 

     <div class="modal-body"> 

      <img src="Wedding%20Invites.jpg"> 


     </div> 

     <div class="modal-footer"> 

      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 

      <button type="button" class="btn btn-primary">Save changes</button> 

     </div> 

     </div> 

    </div> 

    </div> 

</div> 


</body> 
</hmtl> 

<script> 


$(document).ready(function(){ 

$('#box1modal').click(function(){ 
alert("btn click") 
$('#myModal').modal('show') 
}); 

}); 

</script> 
0

您已將數據目標作爲examplemodal和div的id作爲mymodal。兩者應該是一樣的,這就是問題所在。