我们可以在asp.net页面中使用$(文件)。就绪()?

问题描述:

我有一个错误尝试使用$(文件)。就绪()作为上述形象。
应我尝试怎么解决这个问题?

I have an error trying to use $(document).ready() as in the above image. What should i try to solve this problem ?

编辑23/05/2011 10:54

Edit 23/05/2011 10:54

我有一个线索。
我是从页的母版继承工作。

I have got a clue. The page i am working inherit from masterpage

在母版页这code是不行的,不同的路径,也许问题

In master page this code isn't work, maybe problem of different path

<head id="Head1" runat="server">
<title>Back Office</title>
<link href="~/Styles/MasterPage.css" rel="stylesheet" type="text/css" />
<link href="Styles/custom-theme/jquery-ui-1.8.12.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery-1.5.1.min.js"></script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>

这code不似乎工作

在母版页的身体,有一个脚本管理器和jQuery是存在的,
这使得jQuery的作品,是因为我们使用的ScriptManager在体内,使的document.ready是不是工作?

On the body of master page, there is a script manager and jquery is there, This make the jQuery works, is because we use scriptmanager in the body so that the document.ready is not work ?

            <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
                <Scripts>
                    <asp:ScriptReference Path="~/Scripts/jquery-1.5.1.min.js" />
                </Scripts>
            </asp:ScriptManager>
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
            </asp:ContentPlaceHolder>

我已经找到了问题。

I have found the problems.

问题是jQuery的code是在母版,在脚本管理器,脚本经理是人体内标签内。

The problem is the jquery code is on the masterpage, in the script manager, and script manager is in inside the body tag.

在的document.ready是页面上的标题标记,母​​版页上的继承,因此前的code到excuting到身体,jQuery是尚未包括和笏是错误。

the document.ready is on the header tag on page that inherit on master page, so before the code to excuting to the body, the jquery is not included yet and that wat it is error.

要解决这个问题最简单的方法是,我必须移动的JavaScript code在body标签的底部。
解决的正确方法,我仍然无法找到的是把JavaScript的包括在头code。但我没有找到工作,又一种方式。我的母版页和页面继承的是不同的充道路。我找了很多技术,如,但他们没有工作。

The easiest way to solve this is, i have to move javascript code in the bottom of body tag. The proper way to solve, which i still can't find is to put the javascript include code in the header. but i don't find a way that work yet. My master page and inherit page is on the differnt path. I have find a lot of technique such as but none of them work.

取出所有其他的JavaScript包括除了jQuery的-1.5.1.min.js。只用一个包括试试吧。如果这样的作品,添加其他包括回一次,直到你得到的错误。如果它不只有包括jQuery脚本工作,它就有可能是不正确的路径指向。

Take out all of the other javascript includes except for jquery-1.5.1.min.js. Try it with just that one include. If that works, add the other includes back in one at a time until you get the error. If it doesn't work with just the jQuery script included, chances are it's not pointing at the correct path.

简短的回答虽然,是的,你可以使用jQuery和ASP.NET页面的document.ready。

Short answer though, yes, you can use jQuery and document.ready in an ASP.NET page.