javascript错误: this.节点为空或不是对象

标签 javascript asp.net visual-studio-2010 .net-3.5 runtime-error

我正在使用 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.
});

More info on jQuery document ready .

关于javascript错误: this.节点为空或不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4036735/

相关文章:

c# - 如何在 ListView 中显示列表项?

asp.net - 如何在asp.net中使用css进行web服务器控制?

javascript - 使用 jquery 获取数据和元素

javascript - js 如何通过 try catch 正确使用 block 级变量

javascript - LESS 在线发布网站后动态样式表语言不起作用

java - 将小程序与 Telerik 控件一起使用时出现 ClassNotFoundException

javascript - ASP.NET/JavaScript : How to open a link in a new web page set to a width 640px and height 480px?

无法让 orcc 代码在 Visual Studio 2010 中使用 C 后端运行

javascript - Redux 在 document.open() 之后没有注册 Action

javascript - 如何修复 cy.route() 数据类型响应问题?