您可以在 js 文件中包含以下 javascript 代码以及其余的 js 库,
function showModal(message, closeCaption, options) {
$(document).ready(function () {
var modalDialogHTML = '<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><h4 class="modal-title">Modal title</h4>' +
'</div>' +
'<div class="modal-body">' + message + '</div>' +
'<div class="modal-footer">' +
'<button type="button" class="btn btn-default" data-dismiss="modal">' + (closeCaption ? closeCaption : 'Close') + '</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$('body').append(modalDialogHTML);
$('#myModal').modal(options);
});
}
然后,showModal("the message");
当您检测到未登录用户时,您可以动态调用。
http://jsfiddle.net/v8USb/