[英]How to display Bootstrap 3 alert with reference to external JavaScript
I have a webpage with Bootstrap 3 and I tried below code to display alert box. 我有一个带有Bootstrap 3的网页,并且尝试了以下代码来显示警报框。
<button class="btn btn-warning" onclick="warning('Are you sure ?')">Warning</button>
its working fine with this below Javascript on my web page. 我的网页上的Javascript下面的代码可以正常工作。
window.error = function(msg) {
var dom = '<div class="top-alert"><div class="alert alert-danger alert-dismissible fade in " role="alert"><i class="glyphicon glyphicon-exclamation-sign"></i> ' + msg + '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div></div>';
var jdom = $(dom);
jdom.hide();
$("#id_template").append(jdom);
jdom.fadeIn();
setTimeout(function() {
jdom.fadeOut(function() {
jdom.remove();
});
}, 6000);
}
For an external JavaScript file the warning() function is giving ReferenceError: warning is not defined 对于外部JavaScript文件,warning()函数给出ReferenceError:警告未定义
My external Js given below for example 我的外部Js例如
// JavaScript Document
function fetch(){
var user = $("#id_owner").val();
var firstname = $("#id_fname").val();
if(firstname == ""){
warning('You must enter First Name.');
return false;
}
}
You must try below code directly from your external javascript. 您必须直接从外部javascript尝试以下代码。
if(firstname == ""){
var dom = '<div id="modals" class="alert alert-danger" style="display:none;"><button data-dismiss="alert" class="close" type="button">×</button><span class="entypo-attention"></span> <strong>Waring</strong> You must enter First Name.</div>';
var jdom = $(dom);
jdom.hide();
$("id_template").append(jdom);
jdom.fadeIn();
setTimeout(function() {
jdom.fadeOut(function() {
jdom.remove();
});
}, 6000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.