JavaScript运行时错误:对象不支持属性或方法'jqGrid'

时间:2022-03-05 19:20:10

I get the exception - "JavaScript runtime error: Object doesn't support property or method 'jqGrid'" when I move below block from maincontent of content page to header section of master page.

我得到异常 - “JavaScript运行时错误:对象不支持属性或方法'jqGrid'”当我从内容页面的maincontent到主页面的标题部分移动到块下面时。

<link href="../Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="../Content/jquery.jqGrid/jquery-ui-custom.css" rel="stylesheet" />
<script src="../Scripts/jquery-1.9.1.min.js"></script>
<script src="../Scripts/jquery.jqGrid.js"></script>
<script src="../Scripts/i18n/grid.locale-en.js"></script>


It only works when I place this block in trailing section of master page.
Could someone help me understand why it works only when I place this block in trailing section of master page but not in header section? I think this has something to do with loading dependencies and initialization of jqGrid, however I need concrete understanding.

它仅在我将此块放在母版页的尾部时才有效。有人可以帮助我理解为什么只有当我将这个块放在母版的尾部而不是标题部分时它才有效?我认为这与加载jqGrid的依赖关系和初始化有关,但我需要具体的理解。

1 个解决方案

#1


5  

You have to wait until DOM finishes loading. Then you can apply your scripts. Since, in your master page, you are using the script at the bottom, since the parser uses top down approach, it executes the script, after the body is completed loading.

你必须等到DOM完成加载。然后,您可以应用您的脚本。因为,在您的母版页中,您使用的是底部的脚本,因为解析器使用自顶向下的方法,所以它在完成加载主体后执行脚本。

So, if you do want to put in head section, ensure that all your script is inside document.ready() function

因此,如果您确实要放入head部分,请确保所有脚本都在document.ready()函数中

Also , know that it is always a best practice to put all your scripts at bottom rather than at the header.

此外,要知道将所有脚本放在底部而不是标题处始终是最佳做法。

This is a good performance indicator. Also it avoids the usage of ready function

这是一个很好的绩效指标。它也避免使用就绪功能

Hope this helps..

希望这可以帮助..

#1


5  

You have to wait until DOM finishes loading. Then you can apply your scripts. Since, in your master page, you are using the script at the bottom, since the parser uses top down approach, it executes the script, after the body is completed loading.

你必须等到DOM完成加载。然后,您可以应用您的脚本。因为,在您的母版页中,您使用的是底部的脚本,因为解析器使用自顶向下的方法,所以它在完成加载主体后执行脚本。

So, if you do want to put in head section, ensure that all your script is inside document.ready() function

因此,如果您确实要放入head部分,请确保所有脚本都在document.ready()函数中

Also , know that it is always a best practice to put all your scripts at bottom rather than at the header.

此外,要知道将所有脚本放在底部而不是标题处始终是最佳做法。

This is a good performance indicator. Also it avoids the usage of ready function

这是一个很好的绩效指标。它也避免使用就绪功能

Hope this helps..

希望这可以帮助..