我试图在推送 save changes 时捕获点击事件。

由于某种原因,我无法捕捉点击事件。

为什么?

<script>
            $('#inviteRequest').click(function(){
//                e.preventDefault();
                console.log(1);
                $('#myModalInviteDestination').modal('hide');
            });

        </script>

        <!-- Modal -->
        <div class="modal fade" id="myModalInviteDestination" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Enter your friends email address</h4>
                    </div>
                    <div class="modal-body">
                        <textarea rows="5" cols="68" name="invites"></textarea>
                        <div>use ; as delimiter</div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" id="inviteRequest">Save changes</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

最佳答案

您需要将其包装在 document.ready 中:

$(function() {
    $('#inviteRequest').click(function(){
        console.log(1);
        $('#myModalInviteDestination').modal('hide');
    });
});

关于javascript - 引导模式上未触发单击事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20047852/

10-12 13:19