很简单,这个问题通常是JQuery库没有正确的被调用,导致无法识别$关键字。
可以先将JQuery的src设置成在线包,试用一下,如下代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery - $ is not defined</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("jQuery is working perfectly.");
});
});
</script>
</head>
<body>
<button type="button">Test jQuery Code</button>
</body>
</html>
确认Jquery能跑起来后,再逐步确认到底是JQuery引用路径问题,还是包本身问题等等。
评论
No comments yet.