繁体   English   中英

如何获取触发 change() 函数的选择选项的数据值并使用它打开其模式?

[英]How do I get data-value of the select option where I triggered the change() function and use that to open its modal?

我有一个选择输入下拉列表,它在选择“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'));
});

这是我的 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() 函数的选择选项的数据值? 我不确定我是否说得通,但我希望你明白我的意思。 我希望能够仅显示我进行选择的某个数据值的模式。

像这样的事情会起作用:

$('.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM