作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在关注这个 ( Bootstrap modal to confirm table row delete ) 但我不确定为什么,但是模态对话框没有出现。
虽然我的表是由我的 jQuery 代码动态创建的,但我基本上希望做同样的事情:
$("#guests_table > tbody:last").append(
"<tr class='btnDelete' data-id='" + guest.guest_id + "'>"
+ "<td>" + guest.guest_first_name + "</td>"
+ "<td>" + guest.guest_last_name + "</td>"
+ "<td>" + guest.guest_email + "</td>"
+ "<td>" + "<a href='editguest.html?guestId=" + guest.guest_id + "&hostId=" + hostId + "®istryId=" + guest.registry_id + " '>"
+ "<img src='images/edit26.png' height='60%' width='60%'></a></td>"
+ "<td><button class='btnDelete' href=''>delete</button></td>"
+ "</tr>");
});
在 HTML 页面的头部:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
模态对话框:
<!-- start: Delete Coupon Modal -->
<div class="modal fade" id="myModal" 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>
<h3 class="modal-title" id="myModalLabel">Warning!</h3>
</div>
<div class="modal-body">
<h4>Are you sure you want to DELETE?</h4>
</div>
<!--/modal-body-collapse -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="btnDelteYes" href="#">Yes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
<!--/modal-footer-collapse -->
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
JS页面中的按钮调用:
$('btn.btnDelete').on('click', function (e) {
e.preventDefault();
var id = $(this).closest('tr').data('id');
$('#myModal').data('id', id).modal('show');
});
$('#btnDelteYes').click(function () {
var id = $('#myModal').data('id');
$('[data-id=' + id + ']').remove();
$('#myModal').modal('hide');
});
删除时,我有一个要删除的 API 调用,但我只是在努力让对话框出现。知道为什么吗?
谢谢
最佳答案
当您绑定(bind)删除按钮点击事件时,您的 CSS 选择器出现问题。应该是.btn.btnDelete
,注意.
在前面还是它。
$('.btn.btnDelete').on('click', function (e) {
e.preventDefault();
var id = $(this).closest('tr').data('id');
$('#myModal').data('id', id).modal('show');
});
还要确保删除按钮具有类 btn
才能正常工作:
<button class='btn btnDelete' href=''>delete</button>
<!-- add btn ^ class -->
关于javascript - 确认删除的模态对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791944/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!