模态按钮没有触发其点击事件

时间:2016-04-14 19:35:24

标签: javascript jquery modal-dialog bootstrap-modal

我有这个模态并且在SaveChangesofCollectorID id

 <div  class="modal fade" id="mymodal" role="dialog" >
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
               <input id="ToDate" name="ToDate" readonly="readonly"/>

            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal" style="width:40px;">no</button>
              <button id="SaveChangesofCollectorID" data-dismiss="modal" type="button" class="btn btn-default"  style="width:40px;">yes</button>
            </div>
          </div>

        </div>
它没有发动它的事件 ,或者只是发出第一个警报, 甚至我删除了data-dismiss =&#34; modal&#34; 这是我的实验

        $("#SaveChangesofCollectorID").click(function () {
            alert("inserted here");
            $.ajax({
                type: "POST",
                url: "UnloadingCalendar.aspx/SaveChangesofCollector",
                data: JSON.stringify({ CollectorID: CollectorID, FromDate: startday, ToDate: EndDate, DaysCount: countdays }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {

                    OpenConfirmationModal();
                },
                error: function (msg) {
                    alert(msg.d);
                },
                complete: function () {

                }
            });


        });

  </div>

1 个答案:

答案 0 :(得分:0)

这是一个工作小提琴:https://jsfiddle.net/code4pi/6rvd073L/

您的代码没有任何问题,如果您要将其内联(或者更好,将js移动到自己的文件中),您只需将js包装在脚本标记中:

<script>
    $("#SaveChangesofCollectorID").click(function () {
        alert("inserted here");
        $.ajax({
            type: "POST",
            url: "UnloadingCalendar.aspx/SaveChangesofCollector",
            data: JSON.stringify({ CollectorID: CollectorID, FromDate: startday, ToDate: EndDate, DaysCount: countdays }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {

                OpenConfirmationModal();
            },
            error: function (msg) {
                alert(msg.d);
            },
            complete: function () {

            }
        });


    });
</script>