在函数内部插入swal不工作

时间:2018-03-11 18:18:51

标签: javascript php sweetalert

我尝试了sweetalert.com的默认代码,它正在工作意味着我有我的导入链接。我试图把它放在函数内部由于某种原因。这是我的代码:

此swal代码无效

<html>
<head>
         <script src="https://code.jquery.com/jquery-3.2.1.min.js">
 </script>

    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js">
 </script>
 </head>
<title></title>
<body>
<form onclick="myFunctions()">  
<button> Try </button>
<script>
function myFunctions(){
swal("Hello world!");
}
</script>
</form>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

你忘了导入CDN:

<html>
<head>
<title>Title</title>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
</head>

<body>

<button id="clickme" > Try </button>




<script>

$(document).ready(

function myFunctions(){

    $("#clickme").click(function(){
        swal("Hello world!");
    });


}
)
</script>
</body>
</html>