click event not triggered on bootstrap modal
2024-08-30 19:07:54
I am trying to catch the click event when save changes
is 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 -->
Answers
You need to wrap this in a document.ready:
$(function() {
$('#inviteRequest').click(function(){
console.log(1);
$('#myModalInviteDestination').modal('hide');
});
});
Your element #inviteRequest
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();
最新文章
- django系列--第一节
- Moon.Orm 5.0(MQL版)分页功能的设计(求指教,邀请您的加入)
- ARP协议工作流程
- awk系列:在awk中如何使用流程控制语句
- SQL Server 2012将数据库备份到网络中的共享文件夹
- Hadoop build error java.lang.NoClassDefFoundError: org/sonatype/aether/graph/DependencyFilter
- mysql数据库管理备份运维常用命令
- html5 中常用的标签和属性
- ajax用户名校验demo详解
- PHP根据经纬度,计算2点之间的距离的2种方法
- final的深入理解 - final数据
- wireshark 过滤条件汇总
- js与DOM初步:访问html元素
- java8-Stream之数值流
- 流式大数据计算实践(3)----高可用的Hadoop集群
- iOS开发基础-UITableView控件简单介绍
- js中的回调函数 和promise解决异步操作中的回调地狱问题。
- Linux的基础命令, django的安装与使用
- [原][OSG]OSG例子程序简介
- 天地图常用WMTS配置参数
热门文章
- (十八)python 3 回调函数
- NGINX模块(一)
- xtu summer individual 2 E - Double Profiles
- python002 Python3 基础语法
- Flask--登录检查(简单篇)---xunfeng巡风实例篇
- 让你的 CDN 费用省 50% 以上!图片瘦身的正确姿势
- CodeForces 444C 节点更新求变化值的和
- 【判连通】HDU 6113 度度熊的01世界
- [Vijos] SuperBrother打鼹鼠
- python学习之-- assert断言