开发者

javascript error: this.node is null or not an object

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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜