I have a select input dropdown that calls a function (openModal) when the "3" value is selected:$('.statusButtonChange').change(function () { if ($(this).val() == '1') changeStatus($(this).attr('data-value')); else if ($(this).val() == '3') openModal(); else changeWork($(this).attr('data-value'));});这是我的 openModal 函数:function openModal(x) {(function ($) { $('#alarm-DATAVALUEOFTHESELECTOPTIONTHATTRIGGEREDTHISFUNCTION').modal('show'); })(jQuery);}还有我的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 --> 我有多个模式,具有不同的 div id,具体取决于我的 PHP 代码中的数据值。数据值也可以从我的选择 html 中的数据值中获取。有没有办法获取我触发 change() 函数的选择选项的数据值?我不确定我是否有道理,但我希望你明白我的意思。我希望能够只显示我选择的某个数据值的模态。
1 回答

回首忆惘然
TA贡献1847条经验 获得超11个赞
像这样的东西会起作用:
$('.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');
}
- 1 回答
- 0 关注
- 150 浏览
添加回答
举报
0/150
提交
取消