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

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() 函数的选择选项的数据值?我不确定我是否有道理,但我希望你明白我的意思。我希望能够只显示我选择的某个数据值的模态。


繁花如伊
浏览 151回答 1
1回答

回首忆惘然

像这样的东西会起作用:$('.statusButtonChange').change(function () {&nbsp; &nbsp;if ($(this).val() == '1') changeStatus($(this).attr('data-value'));&nbsp; &nbsp;else if ($(this).val() == '3')&nbsp; openModal($(this).attr('data-value'));&nbsp; &nbsp;else changeWork($(this).attr('data-value'));});...function openModal(x) {&nbsp; &nbsp;$('#alarm-' + x).modal('show');}
打开App,查看更多内容
随时随地看视频慕课网APP