从 Javascript 函数调用 Bootbox.js
Call Bootbox.js from Javascript function
我需要 运行 bootbox 我有下一个代码:
<script>
function validateForm() {
var x1 = document.forms["contactform"]["name"].value;
if (x1 == null || x1 == "") {
alert("Please Enter name"); // I WANT CALL Bootboxjs HERE
return false;
}
}
</script>
所以我想用这个替换标准 javascript 警报:
bootbox.alert("Hello world!", function() {
Example.show("Hello world callback");
});
我尝试将 botbox.alert
粘贴到 javascript 函数中,但没有成功。
我该怎么做?
您想要实现的是替换默认的 javascript 警报方法
此功能在所有浏览器中都可用,没有任何问题,只需使用
覆盖警报方法
window.alert = function(message){
bootbox.alert(message, function() {
// execute a predefined callback
});
}
// and call like
alert("Hello world"); // shows bootbox alert
如果您想包含回调:
// include this before any alert call is executed in any script
window.alert = function(message,callback){
bootbox.alert(message, callback);
}
// and call like
alert("Hello world",function(){
console.log("custom callback");
}); // shows bootbox alert
我需要 运行 bootbox 我有下一个代码:
<script>
function validateForm() {
var x1 = document.forms["contactform"]["name"].value;
if (x1 == null || x1 == "") {
alert("Please Enter name"); // I WANT CALL Bootboxjs HERE
return false;
}
}
</script>
所以我想用这个替换标准 javascript 警报:
bootbox.alert("Hello world!", function() {
Example.show("Hello world callback");
});
我尝试将 botbox.alert
粘贴到 javascript 函数中,但没有成功。
我该怎么做?
您想要实现的是替换默认的 javascript 警报方法
此功能在所有浏览器中都可用,没有任何问题,只需使用
覆盖警报方法window.alert = function(message){
bootbox.alert(message, function() {
// execute a predefined callback
});
}
// and call like
alert("Hello world"); // shows bootbox alert
如果您想包含回调:
// include this before any alert call is executed in any script
window.alert = function(message,callback){
bootbox.alert(message, callback);
}
// and call like
alert("Hello world",function(){
console.log("custom callback");
}); // shows bootbox alert