jQuery按钮单击不会运行

jQuery按钮单击不会运行,jquery,onclick,Jquery,Onclick,我无法运行这个简单的脚本,并且已经盯着它看了一段时间,没有看到任何语法错误。只需单击即可显示警报 <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type='text/javascript'> $(document).ready(function() { $("#a

我无法运行这个简单的脚本,并且已经盯着它看了一段时间,没有看到任何语法错误。只需单击即可显示警报

<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>

$(文档).ready(函数(){
$(“#验证按钮”)。单击(函数(){
警报(“点击”);
});
});
证明…是真实的

您正在使用web浏览器直接打开文件
/
是当前协议(即
文件://
)的缩写,因此jQuery不是从Google的CDN加载的

您需要通过在这一行的
/
之前添加
http:
来明确指定协议:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

我还要添加一个doctype:

<!DOCTYPE html>

您正在使用web浏览器直接打开文件
/
是当前协议(即
文件://
)的缩写,因此jQuery不是从Google的CDN加载的

您需要通过在这一行的
/
之前添加
http:
来明确指定协议:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

我还要添加一个doctype:

<!DOCTYPE html>

您也可以尝试以下方法:

使用MediaTemple提供的jQuery CDN

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

使用微软的CDN

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>

作为jqueryjs文件的替代

我建议这样做:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>  
<script>  
     // Fallback to loading jQuery from a local path if the CDN is unavailable  
     (window.jQuery || document.write('<script src="/scripts/jquery-1.9.0.min.js"><\/script>'));  
</script>

//如果CDN不可用,则回退到从本地路径加载jQuery
(window.jQuery | | document.write(“”));

您也可以尝试以下方法:

使用MediaTemple提供的jQuery CDN

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

使用微软的CDN

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>

作为jqueryjs文件的替代

我建议这样做:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>  
<script>  
     // Fallback to loading jQuery from a local path if the CDN is unavailable  
     (window.jQuery || document.write('<script src="/scripts/jquery-1.9.0.min.js"><\/script>'));  
</script>

//如果CDN不可用,则回退到从本地路径加载jQuery
(window.jQuery | | document.write(“”));

是否在http://中打开文件?如果您在file://中打开它,它将无法工作。浏览器中的控制台会说什么?这不是在本地文件中运行的,是吗?它是本地文件,为什么不工作?在JSFIDLE中尝试了此操作,我可以看到警报。您是在http://中打开文件的吗?如果您在file://中打开它,它将无法工作。浏览器中的控制台会说什么?这不是在本地文件中运行的,是吗?它是本地文件,为什么不工作?在JSFIDLE中尝试了这一点,我可以看到警报。