javascript 未捕获的类型错误:无法读取 null 的属性“就绪”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31202033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot read property 'ready' of null
提问by G droid
I know this question has been asked probably too many times before but none of those solutions has been able to help me out.I keep getting the above error even if I have everything in place AFAIK.
我知道这个问题之前可能已经被问过太多次了,但这些解决方案都无法帮助我。即使我已经准备好所有东西,我也会不断收到上述错误。
I have included the button in the html code but when i try to find them through jquery error: "Cannot read property 'ready' of null" occurs moreover it does not even recognize the document.ready function. Here is my full code:
我已经在 html 代码中包含了按钮,但是当我尝试通过 jquery 找到它们时出现错误:“无法读取 null 的属性 'ready'”,而且它甚至无法识别 document.ready 函数。这是我的完整代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery.js"></script>
<script src="Scripts/jsencrypt.js"></script>
<script src="Scripts/jsencrypt.min.js"></script>
<script src="Scripts/jsencrypt.min.js"></script>
<script src="Scripts/jsencrypt.js"></script>
<script type="text/javascript" src="System.js"></script>
<script type="text/javascript" src="System.IO.js"></script>
<script type="text/javascript" src="System.BigInt.js"></script>
<script type="text/javascript" src="System.BitConverter.js"></script>
<script type="text/javascript" src="System.Convert.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.HMACSHA1.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.RSA.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.SHA1.js"></script>
<script type="text/javascript" src="System.Text.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert("button");
});
// debugger;
// var element = document.getElementById("btntest");
//$("#btntest").click(function () {
// alert("button");
//});
</script>
</head>
<body>
<input type="button" id="btntest" value="Test" />
<span>Name:</span>
<input type="text" id="txtName" />
<br />
<br />
<input type="button" id="btnSend" value="Send" />
</body>
</html>
Any suggestions to resolve this would be really appreciated.
任何解决此问题的建议将不胜感激。
回答by Rahul Shenoy
Have you tried using a CDN for example - https://code.jquery.com/jquery-1.11.3.min.js
例如,您是否尝试过使用 CDN - https://code.jquery.com/jquery-1.11.3.min.js
I don't see any problem with the code as long as $ has been overwritten by any other reference below it. If the code does not work with CDN reference, you can also try adding the jquery reference at the end.
只要 $ 被下面的任何其他引用覆盖,我就看不到代码有任何问题。如果代码不支持 CDN 引用,您也可以尝试在最后添加 jquery 引用。
回答by G droid
It was my bad.Changing the order of the jquery files did the trick. Added the reference of jquery and jquery.min files at the bottom of the other .js files. Might help some one as well.
这是我的错。更改 jquery 文件的顺序可以解决问题。在其他 .js 文件的底部添加了 jquery 和 jquery.min 文件的引用。也可能对某人有所帮助。
<script type="text/javascript" src="System.js"></script>
<script type="text/javascript" src="System.IO.js"></script>
<script type="text/javascript" src="System.BigInt.js"></script>
<script type="text/javascript" src="System.BitConverter.js"></script>
<script type="text/javascript" src="System.Convert.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.HMACSHA1.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.RSA.js"></script>
<script type="text/javascript" src="System.Security.Cryptography.SHA1.js"></script>
<script type="text/javascript" src="System.Text.js"></script>
<script src="Scripts/jquery.js">