我正在使用 ASP.NET 3.5、C#、Visual Studio 2010。我制作了一个主文件和一个使用该主文件的默认页面。我放置了几个asp:contentplaceholders
在母版中以及使用该母版的页面中的相应代码。我还在内容页面(而不是主页面)中插入了这样的 JavaScript:
<asp:Content ID="Content6" ContentPlaceHolderID="Mainpage" Runat="Server">
<script src="path1" type="text/javascript"></script>
<script src="path2" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var options = {
//some java code
};
$(".mycssclass").effect(options);
});
</script>
</asp:Content>
在运行网站时,我在 Visual Studio 中收到以下运行时错误:
Microsoft JScript runtime error: 'this.node' is null or not an object
它指向 JavaScript 中的一些函数,例如
this.node.onload=function(){..............//I am not a java guy so do not know much about this
我哪里出错了?为什么网站编译正确但抛出此运行时错误?
我还尝试在 <head>
的主文件中插入此 java 代码。 ,但同样的错误。这很紧急,所以如果有经验的人可以准确指出代码的确切位置,这将可以快速解决我的问题。
最佳答案
您是否包含了对 jQuery 库的引用?一个好的做法是将 jQuery 包含在 Master 中。
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<!-- the remainder of your .js references should follow-->
</head>
如果您打算让该脚本在“页面加载”时运行,请确保其设置正确:
$(document).ready(function() {
// put all your jQuery goodness in here.
});
关于javascript错误: this.节点为空或不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4036735/