我不能让这个简单的脚本运行并且暂时盯着它看一段时间并且没有看到任何语法错误.只需要点击即可显示警报.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$("#authenticate_button").click(function() {
alert("click");
});
});
</script>
</head>
<body>
<input id="code" type="text">
<button id='authenticate_button'>Authenticate</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您正在使用Web浏览器直接打开文件.//是您当前协议的缩写(即file://),因此jQuery不会从Google的CDN加载.
您需要通过在此行http:之前添加来明确指定协议//:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我还要添加一个doctype:
<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)