模态无法访问其显示功能

modal can't access its show function

本文关键字:显示 功能 访问 模态      更新时间:2024-04-04
$('#modalSetDonationsProducts').on('show.bs.modal', function (e) {
    alert("dljasld");
    rowNumber = 1;
    $('#tblEmployees tbody tr').remove("tr:gt(0)");
    alert("enterd");
    var itemname = $(this).parent().parent().find(rowData["ItemName"]).val()
    alert(itemname);              
    $(e.currentTarget).find('input[name="item"]').val(itemName);
    $(e.currentTarget).find('input[name="description"]').val(itemName);
    $(e.currentTarget).find('input[name="item"]').enabled = false;      
});

我有这个功能和模态

<div class="modal modal-flex " id="modalSetDonationsProducts">
    <div class="modal-dialog" style="min-width: 900px; max-width:1000px;width:auto">
        <div class="modal-content">
            <div class="modal-header" style="width:100%;">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
                <h4 class="modal-title">&nbsp;<%= GetLocalResourceObject("addnewitem")%></h4>
            </div>
            <div class="modal-body">
                <p><%= GetLocalResourceObject("addnewitem")%></p>
                <div class="table-responsive">
                    <table class="table" id="tblEmployees">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="rowID1">
                                <td>1</td>                                     
                                <td>
                                    <input type="text" style="min-width:230px" readonly="readonly" name="item" value="" /></td>   </tr>
                        </tbody>
                    </table>
                </div> </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"></button>
                <button type="button" onclick="SaveProducts();" class="btn btn-green ladda-button">                           
                </button>                       
            </div>
        </div>
    </div>
</div>

我用这个称呼模态

<a data-toggle='"modal'" href='"#modalSetDonationsProducts'"   class='"btn btn-green'" name='"btnSplit'">add</a>

已经做的是:

 1.模型正确打开。      2.它无法访问$('#modalSetDonationsProducts'(.on('show.bs.modal',函数(e(并至少显示第一个警报。 3.我的模态调用来自另一个表的按钮,我只想通过parent.find方式设置输入名称="项目"。

工作小提琴:https://jsfiddle.net/3rfb4vny/

我猜你的定位元素出错了,我已经尝试过你的 HTML 和 JS 事件

$('#modalSetDonationsProducts').on('show.bs.modal', function (e) {
    alert("displaying");
});