Dr.*_*eon 13 html javascript jquery modal-dialog twitter-bootstrap
好吧,我绝不是一个JavaScript大师,也许我还在考虑桌面软件开发,但这正是我想要实现的:
题 :
我的意思是 :
这是我的模态的HTML代码(按钮应该 - 以某种方式 - 通过他们的onclickjavascript例程进行操作?) - 也注意到它将#confirmMessage是可变的.
<div class="modal fade hide" id="confirmAlert">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3 id="confirmTitle">Are you sure?</h3>
</div>
<div class="modal-body">
<p id="confirmMessage">Body</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
<a href="#" class="btn btn-danger">Yes</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
只是一个想法:
checkBeforeExec(message,functionToExec)#confirmMessage为消息并且是'href tojavascript:functionToExec我知道这听起来有点令人困惑 - 但我根本不知道最友好的javascript方式是什么...
Hac*_*ese 13
我创建了一个围绕modal的对话管理器,其中包含confirm辅助函数,基本上就是这样:
var callback = function(result) {
alert(result);
}); // define your callback somewhere
$('#confirmAlert').on('click', '.btn, .close', function() {
$(this).addClass('modal-result'); // mark which button was clicked
}).on('hidden', function() {
var result = $(this).find('.modal-result').filter('.btn-danger').length > 0; // attempt to filter by what you consider the "YES" button; if it was clicked, result should be true.
callback(result); // invoke the callback with result
});
Run Code Online (Sandbox Code Playgroud)
此外,您应该同时选择取消和是按钮data-dismiss="modal".
请注意,如果您使用的是Bootstrap 3,则应该为hidden.bs.modal事件添加处理程序而不是hidden.
| 归档时间: |
|
| 查看次数: |
28793 次 |
| 最近记录: |