<!doctype html> <html> <head> <meta charset="utf8"> <title>正確寫jQuery</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h3>碧藍空間 </header> <nav> <ul> <li id="TitleInfo">實用鏈接:</li> <li><a href="">新浪</a></li> <li><a href="">百度</a></li> <li><a href="">軍事</a></li> </ul> </nav> <p>記錄你的生活:<textarea cols=50 rows=3 ></textarea> <p><input type='submit' value='存檔'></p> <script type="text/javascript" src="jquery.js"> alert("您將要提交到服務器"); console.log("hello"); $('input[type="submit"]').on("click", function(){ alert("您將要提交到服務器"); }) </script> </body> </html>
上面代碼中的<Script>標簽之間JS代碼不會執行,因為這個標簽已經指明了是引用jQuery文件。應該在新的
<Script>標簽中寫代碼:
<script type="text/javascript" src="jquery.js"> <script> <script> alert("您將要提交到服務器"); console.log("hello"); $('input[type="submit"]').on("click", function(){ alert("您將要提交到服務器"); }) </script>