我正在使用 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.
发布评论
评论(3)
您是否包含对 jQuery 库的引用?一个好的做法是将 jQuery 包含在 Master 中。
如果您打算让该脚本在“页面加载”时运行,请确保正确设置:
有关 jQuery 文档的更多信息已准备就绪。
Have you included a reference to the jQuery library? A good practice would be to have the jQuery include in the Master.
If it's your intention to have that script run on 'page load', then ensure you have it set correctly:
More info on jQuery document ready.
我不确定您正在使用该代码片段做什么,但我认为这不是正确的语法。
您可能应该将其重写为如下所示:
仅将函数传递给 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:
Just passing in the function to the jQuery selector will probably get some wonkiness.
谢谢大家! 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.