<button data-id-site="359319" class="btn btn-warning detailparc"><i class="glyphicon glyphicon-plus"></i> Details</button>
<button data-id-site="56541" class="btn btn-warning detailparc"><i class="glyphicon glyphicon-plus"></i> Details</button>
<button data-id-site="32641" class="btn btn-warning detailparc"><i class="glyphicon glyphicon-plus"></i> Details</button>
<button data-id-site="012438" class="btn btn-warning detailparc"><i class="glyphicon glyphicon-plus"></i> Details</button>
<button data-id-site="545123" class="btn btn-warning detailparc"><i class="glyphicon glyphicon-plus"></i> Details</button>
點擊第一個值,這是我的HTML代碼
$(function(){
$(".detailparc").click(function(){
html = '<div class="modal fade" id="modalDetailParc">';
html+= '<div class="modal-dialog" role="document">';
html+= '<div class="modal-content">';
html+= '<div class="modal-header">';
html+= '<button type="button" class="close" data-dismiss="modal"';
html+= 'aria-label="Close">';
html+= '<span aria-hidden="true">×</span>';
html+= '</button>';
html+= '<h4 class="modal-title">Detail Parc</h4>';
html+= '</div>';
html+= '<div class="modal-body">';
html+= $(this).data('id-site');
html+= '</div>';
html+= '<div class="modal-footer">';
html+= '<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>';
html+= '</div>';
html+= '</div>';
html+= '</div>';
html+= '</div>';
$("#parc").append(html);
$("#modalDetailParc").modal('show');
});
});
這是我的jQuery代碼
我想檢索data-id-site屬性的內容。 當我第一次點擊按鈕時一切都很好,但是當我點擊其他按鈕時,我總能得到我點擊的第一個按鈕的值:/
'$(「#展區」)上(「點擊」清除以前的值之前, '.detailparc',函數(){' –
它似乎很好用https://jsfiddle.net/gzcm5dkh/ – selvarajmas