![](/img/trans.png)
[英]Isit possible to pass value into <div data-value=“” > by jquery?
[英]is it possible to call a modal using its attribute data-value instead of the div id?
我有以下調用模態的函數”
function openModal(x) {
(function ($) {
$('#alarm').modal('show');
})(jQuery);
}
對於模態:
<div id="alarm" class="modal fade modal-alert" data-value="'.$element['eventId'].'">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Title
</div>
<div class="modal-body" id="boxPopUpPushCommand" style="text-align:left !important">
Body texts here
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
嘗試使用數據值而不是 id 打開特定模式?
是的,您可以使用Jquery Attr Selector
$('div[data-value=modalDataValue]').modal('show')
是的,你可以這樣做
$('#alarm[data-value=YOUR_VALUE_YOU_GET_VIA_PHP]').modal('show')
您可以在https://www.w3schools.com/jquery/jquery_ref_selectors.asp了解有關選擇器的更多信息
我建議您通過文檔中唯一的 ID
$(#alarm)
獲取數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.