[英]How do I get data-value of the select option where I triggered the change() function and use that to open its modal?
I have a select input dropdown that calls a function (openModal) when the "3" value is selected:我有一个选择输入下拉列表,它在选择“3”值时调用一个函数(openModal):
$('.statusButtonChange').change(function () {
if ($(this).val() == '1') changeStatus($(this).attr('data-value'));
else if ($(this).val() == '3') openModal();
else changeWork($(this).attr('data-value'));
});
This is my openModal function:这是我的 openModal 函数:
function openModal(x) {
(function ($) {
$('#alarm-DATAVALUEOFTHESELECTOPTIONTHATTRIGGEREDTHISFUNCTION').modal('show');
})(jQuery);
}
And my html:还有我的 html:
<select class="statusButtonChange statusButton " data-value="46024">
<option value="0" selected=""></option>
<option value="1">Close</option>
<option value="2">Open</option>
<option value="3">Disable</option>
</select>
<div id="alarm-'.$element['eventId'].'" class="modal fade modal-alert">
<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 -->
I have multiple modals, with different div ids, depending on the data-value from my PHP code.我有多个模态,具有不同的 div id,具体取决于我的 PHP 代码中的数据值。 Data-value can also be taken from the data-value inside my select html.
数据值也可以从我选择的 html 中的数据值中获取。 Is there a way to get the data-value of the select option where i triggered the change() function?
有没有办法获取我触发 change() 函数的选择选项的数据值? I'm not sure if I made sense but I hope you get what I mean.
我不确定我是否说得通,但我希望你明白我的意思。 I want to be able to show just the modal of a certain data-value where I did the select.
我希望能够仅显示我进行选择的某个数据值的模式。
Something like this will work:像这样的事情会起作用:
$('.statusButtonChange').change(function () {
if ($(this).val() == '1') changeStatus($(this).attr('data-value'));
else if ($(this).val() == '3') openModal($(this).attr('data-value'));
else changeWork($(this).attr('data-value'));
});
... ...
function openModal(x) {
$('#alarm-' + x).modal('show');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.