click event not triggered on bootstrap modal
2016-04-21 16:50
495 查看
I am trying to catch the click event when
save changesis pushed.
For some reason i can't catch the click event.
Why?
<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">×</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 -->
[/code]
Answers
You need to wrap this in a document.ready:
$(function() { $('#inviteRequest').click(function(){ console.log(1); $('#myModalInviteDestination').modal('hide'); }); });
does not exist at the time you try to add an event handler to it. You need to wait for the page to load first. My code is the equivalent to $(document).ready();
Your element [code]#inviteRequest
[/code]
相关文章推荐
- Bootstrap学习笔记(3)--表格\表单\图片
- Bootstrap弹出窗示例
- how to create modals with Bootstrap
- 基于bootstrap的日期插件bootstrap-datetimepicker
- BootStrap table 数据填充与分页
- 解决JS组件bootstrap table分页实现过程中遇到的问题
- 国产bootstrap前端框架 拼图响应式前端框架版响应式后台正式发布
- BootStrap和jQuery相结合实现可编辑表格
- bootstrap组件
- bootstrap初体验--所有图标链接
- BootStrap和jQuery相结合实现可编辑表格
- 解决JS组件bootstrap table分页实现过程中遇到的问题
- django使用bootstrap前端框架
- Bootstrap入门学习(三)——简单项目
- 学习——Bootstrap网格(栅格)系统
- 学习BootStrap框架的一点心得
- Bootstrap well.less 分析
- Bootstrap-fileinput插件使用教程 支持多文件上传
- 基于Bootstrap使用jQuery实现简单可编辑表格
- Bootstrap学习 - JavaScript插件