Sam*_*our 4 javascript asp.net updatepanel twitter-bootstrap-3
这是我的网站 - > www.superim.ir它的模板基础是bootstrap,在导航菜单中,我在下面的代码中使用了一些效果!
$('.productbar .dropdown').on('show.bs.dropdown', function (e) {
$(this).find('.dropdown-menu').first().stop(true, true).fadeIn(300);
$(this).find('.dropdown-menu').first().stop(true, true).animate({ top: "45px" }, 300);
});
$('.productbar .dropdown').on('hide.bs.dropdown', function (e) {
$(this).find('.dropdown-menu').first().stop(true, true).fadeOut(300);
$(this).find('.dropdown-menu').first().stop(true, true).animate({ top: "55px" }, 300);
$(this).find('.sub-menu').hide();
$(this).find('.left-caret').addClass("right-caret").removeClass("left-caret");
});
Run Code Online (Sandbox Code Playgroud)
点击后添加到购物车按钮,更新面板将启动,此后菜单效果不起作用!
解决办法是什么?
这是由于Partial Postback使用而发生的UpdatePanel.在Events您订阅的控件呈现局部因此事件失去.要克服这种情况,您需要重新绑定控件事件.
这是混合传统ASP.Net Ajax和jQuery事件引起的常见问题.当您执行部分回发时,将重新创建DOM并丢失jQuery事件.
例:
<script type="text/javscript">
// bind the events (jQuery way)
$(document).ready(function() {
bindEvents();
});
// attach the event binding function to every partial update
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(evt, args) {
bindEvents();
});
<script/>
Run Code Online (Sandbox Code Playgroud)
阅读有关MSDN上的PageRequest Manager的更多信息
此bindEvents()方法包含在部分页面回发后需要重新加载的所有脚本.
希望这对你有所帮助!
我遇到了同样的问题。我从这个链接得到了帮助。更新 UpdatePanel 时执行 JavaScript
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(
upPanel,
this.GetType(),
"MyAction",
"doMyAction();",
true);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13638 次 |
| 最近记录: |