javascript 错误:this.node 为 null 或不是对象

发布于 2024-09-29 05:11:52 字数 1056 浏览 8 评论 0 原文

我正在使用 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 运行时错误:“this.node”为 null 或不是对象

,它指向 JavaScript 中的某个函数,例如

this.node.onload=function(){..............//I am not a java guy so do not know much about this  

我哪里出错了?为什么网站编译正确但抛出此运行时错误?

我还尝试在 的主文件中插入此 java 代码,但出现同样的错误。这很紧急,所以如果有经验的人可以指出代码的确切位置,这将可以快速解决我的问题。

I am working on ASP.NET 3.5, c#, visual studio 2010. I have made a master file and a default page that uses this master file. I have placed a couple asp:contentplaceholders in the master and corresponding code in the page that uses this master. I have also inserted JavaScript like this in the content page (and not the master):

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

On running the website I get the following runtime error in visual studio:

Microsoft JScript runtime error: 'this.node' is null or not an object

and it point to some function inside the JavaScript like

this.node.onload=function(){..............//I am not a java guy so do not know much about this  

Where am I going wrong? Why does the site compile correctly but throw this runtime error?

I also tried inserting this java code inside the master file in the <head>, but same error. This is urgent please so if someone experienced can pinpoint where exactly to put the code that would be solve my problem quickly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潇烟暮雨 2024-10-06 05:11:52

您是否包含对 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.
});

有关 jQuery 文档的更多信息已准备就绪

Have you included a reference to the jQuery library? A good practice would be to have the jQuery include in the 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>

If it's your intention to have that script run on 'page load', then ensure you have it set correctly:

$(document).ready(function() {
    // put all your jQuery goodness in here.
});

More info on jQuery document ready.

倒带 2024-10-06 05:11:52

我不确定您正在使用该代码片段做什么,但我认为这不是正确的语法。

您可能应该将其重写为如下所示:

$(document).ready(
function () {
        var options = {
            //some java code
        };

        $(".mycssclass").effect(options);
});

仅将函数传递给 jQuery 选择器可能会有些奇怪。

I'm not sure exactly what it is you are doing with that snippet of code, but I don't think it is the proper syntax.

You probably should re-write it to look like this:

$(document).ready(
function () {
        var options = {
            //some java code
        };

        $(".mycssclass").effect(options);
});

Just passing in the function to the jQuery selector will probably get some wonkiness.

尬尬 2024-10-06 05:11:52

谢谢大家! javascript 中的语法或我第一次包含它的位置/页面都没有问题。我刚刚发现错误是在其他地方。此 javascript 适用于 >标签。它会在 > 中缩放图像。标签。我正在使用 >;而是 og >。我一更换它就完美了。感谢大家的宝贵时间和知识分享。

Thank you everyone! there was no problem with either the syntax in the javascript or the location/page where it was first included by me. I just figured out that the mistake was somewhere else. This javascript works on an <img> tag. It zooms the image insdie the <img> tag. I was using the <asp:ImageButton> instead og <img>. It works perfect as soon as I replaced it. Thank you all for your time and the knowledge sharing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文