我正在使用SweetAlert。
http://tristanedwards.me/sweetalert
为此,我需要初始化插件
<script src="lib/sweet-alert.min.js"></script>
<link rel="stylesheet" type="text/css" href="lib/sweet-alert.css">
我需要从我的文件test.js中调用函数swal
,这是:
var accountnumber_c = $('#accountnumber_c').val();
if($('#accountnumber_c').val()=="")
{
return;
}
swal('accountnumber_c');
此works在php文件中,但在test.js中,它给出“未定义swal函数”。
还如何在test.js中初始化插件?
由于要在另一个js文件中引用swwtalert js,您需要使用以下代码来完成它:
var script = document.createElement('script');
script.src = "/path/to/the/other/file.js";
document.getElementsByTagName('script')[0].parentNode.appendChild(script);
//for CSS file
$('head').append('<link rel="stylesheet" href="your/cssfilelocation/filename.css" type="text/css" />');
如果需要在Sweetalert之前包含jquery,请使用类似的代码在其之前添加jquery。