は、だから私は、データ属性のことで、本当に新しいですし、私のjqueryのスキルはかなり初心者くさいです。うまくいけば私はこの権利を求める!jqueryの、データの属性、ブートストラップモーダル
私は、ブートストラップモーダルにコンテンツを追加するために、データ属性を使用します。ユーザーがクリックした画像に応じて、異なる内容のモーダルが得られます。写真は機能します(他の人が書きました)が、テキストを追加する必要があります。ここからは、データ属性に必要なコンテンツを入力します。私は、データmyval一部を追加しました:
<div id="galleryModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<img src="" id="galleryImage" class="img-responsive" />
<div id="galleryText"><!--I added this, this is where I want the data-myval to go (in this div)--></div>
<p>
<br/>
<button class="btn btn-primary btn-lg center-block" data-dismiss="modal" aria-hidden="true">Close <i class="ion-android-close"></i></button>
</p>
</div>
</div>
</div>
</div>
物事を実行しますjqueryのを:ここで
<a href="#galleryModal" class="gallery-box" data-toggle="modal" data-src="./assets/loveinonlandis.jpg" data-myval="this is text">
は、写真要素のそれぞれが使用する、「ジェネリック」モーダルコードです
$('#galleryModal').on('show.bs.modal', function (e) {
$('#galleryImage').attr("src",$(e.relatedTarget).data("src"));
$('#galleryText').data('myval'); //this is the wrong part, but i want to put my text from data-myval into the modal at id galleryText
});
私は、データmyvalの内容から私のテキストを追加できるように、私はこれを書くにはどうすればよい
?
ありがとうございました!
ありがとう溶液で行きます!あなた自身でこれを書く方法を学ぶ方法をお勧めしますか?私はこれに近い何かへのいくつかの方法を推測しましたが、それを働かせませんでした。もっとjqueryを学ぶ必要がある場合は、これも問題ありません。 –