如何在c#中使用RegisterStartupScript和jquery显示一个带有动画的面板

本文关键字:一个 动画 显示 jquery RegisterStartupScript | 更新日期: 2023-09-27 18:08:59

我试图显示一个面板从代码后面的动画。面板显示但没有动画,这是不能工作的行:

Page.ClientScript.RegisterStartupScript(this.GetType(), "ScriptBlock", "$(document).ready(function(){$('#" + pUserActions.ClientID + "').show('"slow'" );});", true);

如何在c#中使用RegisterStartupScript和jquery显示一个带有动画的面板

问题是,在PostBack之后,Panel(或div)已经可见,如果元素已经可见,.show()就不起作用了。例如:

html:

<div style="background-color:red; width:100px; height:100px"></div>
<input type="button" value="Show" id="btnShow" />
<input type="button" value="Hide" id="btnHide" />

js:

$("#btnShow").on("click",function(){$("div").show("slow");});
$("#btnHide").on("click",function(){$("div").hide("slow");});

小提琴:http://jsfiddle.net/hescano/VY9jt/

可以看出,如果在div可见时按下Show按钮,什么也不会发生。在调用服务器端脚本之前尝试让面板可见,您就会明白我的意思。注意,Panel控件的Visible属性将不起作用,因为这会将元素从DOM中移除。