2016-09-29 16 views
1

私は解決策を探していましたが、これを解決するものは何もありません。ロード機能後にモーダルが機能しなくなる

私は自分のコードにモーダルロード関数スクリプトを持っていますが、それは表示されているモーダルですが、コード内のhtmlボタンの1つを使ってdata-dismiss = "modal"命令からモーダルを閉じようとすると、それはモーダルを閉じdoens'ntが、私は「オープンモーダル」ボタンをクリックすると、2つの閉じるボタンはOK仕事:

<script> 
 
setTimeout(function(){ 
 
$(window).load(function(){ 
 
     $('#myModal').modal('show'); 
 
},3000); 
 
</script>
<div class="container"><!-- Trigger the modal with a button --> <button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> 
 
<div id="myModal" class="modal fade" tabindex="-1"> 
 
<div class="modal-dialog"><!-- Modal content--> 
 
<div class="modal-content"> 
 
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">&times;</button> 
 
<h4 class="modal-title">Modal Header</h4> 
 
</div> 
 
<div class="modal-body"> 
 
<p>Some text in the modal.</p> 
 
</div> 
 
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Close</button></div> 
 
</div> 
 
</div> 
 
</div> 
 
</div>

だから、データ・却下=「モーダル」時にのみ動作します私はモーダルを "Open Modal"ボタンから手動でロードしますが、load関数を使用してページloに表示すると機能しません広告。

私は、任意の助けを感謝しますし、任意の提案は歓迎されるだろう、

感謝。

答えて

1

$(window).load(function(){ 
 
    setTimeout(function(){ 
 
     $('#myModal').modal('show'); 
 
    },3000) 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 
<!-- Optional theme --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> 
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 
<div class="container"><!-- Trigger the modal with a button --> <button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> 
 
<div id="myModal" class="modal fade" tabindex="-1"> 
 
<div class="modal-dialog"><!-- Modal content--> 
 
<div class="modal-content"> 
 
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">&times;</button> 
 
<h4 class="modal-title">Modal Header</h4> 
 
</div> 
 
<div class="modal-body"> 
 
<p>Some text in the modal.</p> 
 
</div> 
 
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Close</button></div> 
 
</div> 
 
</div> 
 
</div> 
 
</div>

+0

あなたのJavaScriptは、エラーの原因となります。 – SaJed

+0

こんにちはSaJed、助けてくれてありがとう、私があなたに送ったスクリプトをテストしましたが、それでもまだ動作していません。何らかの形でスクリプトに閉じるボタンをインスタンス化する必要がありますか?なぜなら、ロード機能を使用してロードするときはモーダルにリンクされていないように見えますが、トリガーボタンをロードするときは完全に機能します。 –

+0

スティープコードでbtwを実行すると – SaJed

関連する問題