初次调用JQuery的$()好像没有任何效果。例如在下面的实例中,点击按钮后能够正常弹窗:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>测试网页</title>
<script src="jquery-3.5.1.js"></script>
<script>
window.onload = function() {
var button = document.getElementById("button");
button.onclick = function() {
alert("hello");
}
}
</script>
</head>
<body>
<input type="button" value="按钮" id="button" />
</body>
</html>
但如果换成对JQuery的调用就无法弹窗:
<script>
window.onload = function() {
$("#button").onclick = function() {
alert("hello");
}
}
</script>
代码看了几遍也没看出问题。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…