点击铅笔图标我打开一个模态来编辑输入栏的标签和属性。
$("#myModal").on("show.bs.modal", function(e) {
let someHtml = ``;
$(this).find(".modal-body").append(someHtml);
});
我想从输入字段或从我点击打开模态的按钮周围带来html或一些值。 这些字段不能有唯一标识符。
我可以选择单击按钮以在此事件中打开模式。 还是有更好的替代方法请国家。
答案 0 :(得分:1)
自己触发模态show
事件:
$(document).ready(() => {
$("#myBtn").click(e => {
console.log(e.currentTarget);// your clicked element here
$("#myModal").modal("show");
});
$("#myModal").on('show.bs.modal', function (e) {
});
});
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Events - show.bs.modal</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" id="myBtn">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>The <strong>show.bs.modal</strong> event occurs when the modal is about to be shown.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
希望这有帮助