删除按钮触发模态框

删除按钮触发模态框

<!--确认删除-->
	<div id="deleteModal" class="modal hide fade" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-header">
			<h4 id="myModalLabel">操作确认</h4>
			<a class="close" data-dismiss="modal" aria-hidden="true"
				href="javascript:void();">×</a>
		</div>
		<div class="modal-body">
			<i class="Hui-iconfont">&#xe688;</i> 确认删除选中的项?
		</div>
		<div class="modal-footer">
			<div class="col-xs-6">
				<button class="btn btn-primary" id="deleteConfirm">确定</button>
			</div>
			<div class="col-xs-3">
				<button class="btn btn-primary" data-dismiss="modal"
					aria-hidden="true">取消</button>
			</div>
		</div>
	</div>
	<!--点击删除按钮触发删除操作-->
			$("#deletePostalShift").bind("click", function() {
				if ($("tbody input[type='checkbox']:checked").length == 0) {
					layer.msg('请选择要删除的项');
					return;
				}
				$("#deleteModal").modal('show');
			});
好的,以下是一个简单的JS封装模态框的代码,包含取消、删除和确认按钮,并添加了相应的事件监听器。 HTML部分: ```html <!-- 模态框 --> <div class="modal"> <div class="modal-content"> <p>确定要删除吗?</p> <div class="modal-buttons"> <button id="cancel-btn">取消</button> <button id="delete-btn">删除</button> <button id="confirm-btn">确认</button> </div> </div> </div> <!-- 触发模态框按钮 --> <button id="show-modal-btn">显示模态框</button> ``` CSS部分: ```css /* 遮罩层 */ .modal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); } /* 模态框内容 */ .modal-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 20px; background-color: #fff; border-radius: 5px; text-align: center; } /* 模态框按钮 */ .modal-buttons button { margin: 0 10px; padding: 5px 10px; border-radius: 5px; cursor: pointer; } /* 取消按钮 */ #cancel-btn { background-color: #ccc; color: #000; } /* 删除按钮 */ #delete-btn { background-color: #f00; color: #fff; } /* 确认按钮 */ #confirm-btn { background-color: #0f0; color: #fff; } ``` JS部分: ```javascript // 获取元素 const showModalBtn = document.getElementById("show-modal-btn"); const modal = document.querySelector(".modal"); const cancelBtn = document.getElementById("cancel-btn"); const deleteBtn = document.getElementById("delete-btn"); const confirmBtn = document.getElementById("confirm-btn"); // 显示模态框 showModalBtn.addEventListener("click", () => { modal.style.display = "block"; }); // 隐藏模态框 function hideModal() { modal.style.display = "none"; } // 点击取消按钮 cancelBtn.addEventListener("click", () => { hideModal(); }); // 点击删除按钮 deleteBtn.addEventListener("click", () => { console.log("执行删除操作"); hideModal(); }); // 点击确认按钮 confirmBtn.addEventListener("click", () => { console.log("执行确认操作"); hideModal(); }); ``` 这个模态框的基本功能已经实现了,你可以根据自己的需要进行进一步的定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值