【问题标题】:modal can't access its show functionmodal 无法访问其显示功能
【发布时间】:2016-07-30 20:13:55
【问题描述】:
$('#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 方式设置输入 name="item"。

【问题讨论】:

  • 您似乎错过了; 分号 (alert("dljasld")),因此它正在进一步执行您的 onShowOfModal 事件。
  • 我认为没有效果,还是你的意思是另一个
  • 如果你的 html 是这样的,你不应该转义 title 和 href。
  • 点击显示模态 - 没有转义
  • @PoulBak 没有改变 :( ,模式打开但警报没有触发

标签: javascript c# jquery html twitter-bootstrap


【解决方案1】:

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

我猜你的定位元素有问题,我已经尝试过你的 HTML 和 JS 事件

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

【讨论】:

  • &lt;a title=\"split to more than one product\" href=\"#modalSetDonationsProducts\" data-toggle=\"modal\" class=\"btn btn-green\" name=\"btnSplit\"&gt;Add&lt;/a&gt;我用这个标签调用modal,有什么通知吗? @ameenulla0007
  • 我在 Jquery 中动态调用这个标签,所以我不能删除这个斜杠
  • 哦..你会在你的问题中清楚地提到这一点。实际上,数据切换属性是在准备好 HTML 时定位的。
  • @saraadly,你的功能会很清楚,你在哪里调用了模态调用按钮?以及,试试$('#modalSetDonationsProducts').on('show.bs.modal', function (e) { 没有任何其他声明,只是在那里尝试一个警报,让我知道有什么影响?
猜你喜欢
  • 1970-01-01
  • 2020-12-24
  • 1970-01-01
  • 1970-01-01
  • 2011-12-06
  • 1970-01-01
  • 2021-02-21
  • 2021-09-18
  • 2017-09-26
相关资源
最近更新 更多