如何在页面加载时加载此 javascript 模式?它来自插件“甜蜜警报”。我对 javascript 真的很不好。任何建议一定会有所帮助!
<script>
$(function () {
$('.demo1').click(function(){
swal({
title: "Welcome in Alerts",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
});
});
});
最佳答案
由于您使用的是 jquery,因此您可以使用 document.ready
来包装代码
<script>
$(document).ready(function() {
$('.demo1').click(function() {
swal({
title: "Welcome in Alerts",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
});
});
})
</script>
现在,如果您将此片段放在结束 body
附近,则可以避免 document.ready
<body>
//rest of the dom element
<script>
$('.demo1').click(function() {
swal({
title: "Welcome in Alerts",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
});
});
</script>
</body>
关于javascript - 在页面加载时加载 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41971922/