-1
如何將Html附加到具有相同數據屬性值的相應div? 當按鈕被點擊時,我將一個數據屬性值傳遞給moda,並且它還被添加到模式中的提交按鈕以將值重新傳回。我想找到具有該數據屬性值的元素並將html附加到它。 圖像(1) 如何將Html添加到相同類別的相應div
<button data-media-select="2" data-gallery-position="2" type="button" class="btn btn-success media-modal-btn" >Image (1)</button>
<div data-gallery-position="2" class="popup-gallery"></div>
<button data-media-select="5" data-gallery-position="3" type="button" class="btn btn-warning media-modal-btn" >Images (5)</button>
<div data-gallery-position="3" class="popup-gallery"></div>
Jquery的:
$mediaModalBtn.on('click',function(){
var mediaSelect = $(this).data('media-select')
, galleryPosition = $(this).data('gallery-position');
$.ajax({
url: 'http://example.com/abc/media',
success: function (result) {
$("#mediaModalFiles").html(result);
$('#mediaModal').modal('show');
$('#selectMediaBtn').attr('data-gallery-position',galleryPosition);
$('#mediaModal').checkboxes('max', mediaSelect);
$("#selectMediaBtn").attr('disabled','disabled');
}
});
});
$('body').delegate('input[name="media[]"]','change',function() {
var media = new Array();
$('input[name="media[]"]:checked').each(function() {
media.push(this.value);
});
if (media.length > 0)
{
$("#selectMediaBtn").removeAttr('disabled');
} else {
$("#selectMediaBtn").attr('disabled','disabled');
}
});
$('body').delegate('#selectMediaBtn', 'click', function() {
var galleryPosition = $(this).data('gallery-position')
, targetGalleryPosition = $('.popup-gallery[data-gallery-position = "'+galleryPosition+'" ]')
, media = new Array();
$('input[name="media[]"]:checked').each(function() {
media.push(this.value);
});
if (media.length > 0)
{
$.ajax({
url: 'http://example.com/abc/media/fetch',
data: { media : media },
success: function (result) {
$('#mediaModal').modal('hide');
$(targetGalleryPosition).html(result);
}
});
}
});
最新的問題是什麼?你的代碼中哪部分不起作用? – atmd 2015-02-06 07:51:30
我認爲你正在尋找'$(「。class [data-attribute = value]」)'來選擇給定的框,但我不想破譯你的代碼......(編輯其實你是這麼做的什麼不工作?) – somethinghere 2015-02-06 07:52:29
也許他在做什麼是問答 – 2015-02-06 07:55:52