简体   繁体   English

在首页访问时执行jQuery

[英]Execute jquery on first page visit

I have the following code on my Page_Load method: 我的Page_Load方法上有以下代码:

protected void Page_Load(object sender, EventArgs e)
    {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "$('#sd').slideToggle(200);", true);
    }

This is a jQuery call to toggle the visibility of a div with the id #sd. 这是一个jQuery调用,用于切换ID为#sd的div的可见性。 This seems to work only when this.Page.IsPostBack == true? 这似乎仅在this.Page.IsPostBack == true时才有效。

I have a simple form on that page that works as expected. 我在该页面上有一个简单的表格,可以正常使用。 The form contains an input field that gets processed and returns the result. 该表单包含一个输入字段,该字段将被处理并返回结果。 That works. 这样可行。

However, now i would like to add an option to access the page with the (input) parameter in GET, so processsing could be done on first visit. 但是,现在我想添加一个选项来使用GET中的(input)参数访问页面,因此可以在第一次访问时进行处理。

What is wrong and why is it not working on first visit? 有什么问题,为什么第一次访问时不起作用?

I found it. 我找到了。 Typically, after I posted a question on line: 通常,在我在线发布问题后:

I moved this code 我移动了这段代码

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.flexibleArea.js"></script>

to after the title tag. 到标题标签之后。 It seems like #sd wasn't being loaded at the time of the call. 似乎在调用时未加载#sd。

Could anyone shed more light on this? 有人可以对此进行更多说明吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM