モーダルトリガーボタンをクリックしたときにモーダルボディのテキストを変更しようとしています。しかし、モーダルはオープンですが、モーダル・ボディ・テキストは変化しません。 これはe.preventDefaultは、モーダルテキストを変更した後にモーダルを開くときには機能しません。モーダルは内容を変更せずに開いています
<button type="button" class="btn btn-info open-modal" data-remote="false" data-toggle="modal" data-target="#myModal">Register</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</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 type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
そして、デフォルトのイベントを防止するためのソースモーダルためのコードである
$('.open-modal').click(function(e)
{
e.preventDefault();
alert('hello i am jquery');
$('#myModal').modal('show');
});
なぜ警告( 'こんにちは、私はjqueryの午前');行は実行されていませんか?プログラムで表示するようにモーダルをトリガするために
私はcodepenとしてあなたのコードを実行すると、それが正常に動作します:http://codepen.io/anon/pen/PpdbrJ – mikeg542
Yess。しかし、このコードは私のPCで動作していません。 –