2016-11-06 6 views
0

私はhttp://getbootstrap.com/javascript/#modals-related-targetを使用していますが、自分のプロジェクトでコードを使用すると機能が動作しません。私はこれに非常に新しいので、おそらく何か簡単です。トリガーボタンに基づくさまざまなモーダルコンテンツ

http://hastebin.com/comikucidi.xmlありがとう:

は、ここに私のコードです。

編集: 新しい文書を作成し、ブートストラップページをコピーしました。

代わり
$('#delete').on('show.bs.modal', 

:関数は、まだあなたのモーダルのIDを使用しようと、非既存のIDにハンドラをアタッチしようとしている

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
<meta charset="utf-8"> 
 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<title>Bootstrap - Prebuilt Layout</title> 
 

 
<!-- Bootstrap --> 
 
<link href="css/bootstrap.css" rel="stylesheet"> 
 

 
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
 
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
 
<!--[if lt IE 9]> 
 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
 
    <![endif]--> 
 
</head> 
 
<body> 
 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button> 
 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@fat">Open modal for @fat</button> 
 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">Open modal for @getbootstrap</button> 
 
...more buttons... 
 

 
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
     <h4 class="modal-title" id="exampleModalLabel">New message</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <form> 
 
      <div class="form-group"> 
 
      <label for="recipient-name" class="control-label">Recipient:</label> 
 
      <input type="text" class="form-control" id="recipient-name"> 
 
      </div> 
 
      <div class="form-group"> 
 
      <label for="message-text" class="control-label">Message:</label> 
 
      <textarea class="form-control" id="message-text"></textarea> 
 
      </div> 
 
     </form> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     <button type="button" class="btn btn-primary">Send message</button> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 
<script> 
 
$('#exampleModal').on('show.bs.modal', function (event) { 
 
    var button = $(event.relatedTarget) // Button that triggered the modal 
 
    var recipient = button.data('whatever') // Extract info from data-* attributes 
 
    // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). 
 
    // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. 
 
    var modal = $(this) 
 
    modal.find('.modal-title').text('New message to ' + recipient) 
 
    modal.find('.modal-body input').val(recipient) 
 
}) 
 
</script> 
 
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
<script src="js/jquery-1.11.3.min.js"></script> 
 

 
<!-- Include all compiled plugins (below), or include individual files as needed --> 
 
<script src="js/bootstrap.js"></script> 
 
</body> 
 
</html>

+0

投稿にもコードを追加してください。ここにいるような人はヘルプを受ける機会が増えます。 – GillesC

+0

私は試しましたが、何らかの理由でフォーマットがうまくいきません。 – DanSpedey

答えて

0

が動作していません#exampleModalである。

EDIT:

また、要素が適切に作成された後、あなたのハンドラをアタッチするために、あなたのコードの周りに

$(document).ready(function() { 
    //your code here 
}); 

を追加する必要があります。

+0

ああ、それでも問題は解決していません。 – DanSpedey

+0

私はあなたがテストできる別のものでそれを編集しました;) – Doomshine

+0

あなたが投稿したようにちょうどそれを働かせました、ありがとう:) – DanSpedey

0

jQueryライブラリの呼び出しの最後にスクリプトを入れて、この好き:あなたがこれを行う場合は[こちら]

$('#exampleModal').on('show.bs.modal', function (event) {...} 

(ブートストラップのJavaScriptのプラグインのために必要な)

jQueryの を、それが動作します!

関連する問題