jQuery on: losing attached event after rendering partially by AJAX call
来源:互联网 发布:ubuntu samba 权限 编辑:程序博客网 时间:2024/05/20 22:27
In the menu bar, there is a saved searches link with a number meaning the total number of saved searches.
In one of the page, there is save search button allowing you to save one search, after saved, the number above should be updated by partially rendering the link .
the following code before update:
this.element.find('.savedSearchButton-Menu').on('click', function () {}
Initially, I thought $.on is the same as $.live method, attach the event handler for the selector for ever (now and future), which means event handler is still valid after adding or replacing the DOM elements.. But $.on bind the event handlers only for the selector exists at the time of binding.
if I want to make $.on to work as the same as $.live, I need do the following changes:
$(document.body).on('click','.savedSearchButton-Menu', function(){ if (window.isUserLoggedIn==="true") { window.location.href='/myatc/searches.xhtml'; } else{ $('[id$=myatcLoginLink]').trigger('click'); atc.publish('savedSearchIntent','/myatc/searches.xhtml'); } });
This will bind the event handlers to the DOM selector elements not only now, but also in future. Now the click event fires even the specific selectors are replaced with new DOM elements.
Reference: http://blog.revathskumar.com/2013/10/jquery-on-avoid-losing-event-binding-for-ajaxed-contents.html
0 0
- jQuery on: losing attached event after rendering partially by AJAX call
- How to run an ajax call after another ajax call?
- losing...
- AJAX by JQuery ExtJS
- Custom Editor losing settings on Play
- jquery:$.on(event,[selector],[data],fn)
- Jquery Cross-Domain ajax call using JSONP
- Jquery on() load event on a single element
- Need call beginScene before rendering
- Why fail to catch event after it was raised by FileSystemWatcher
- China Suddenly Losing Ground on US Apparel Import Market
- jQuery的ajax报错:SyntaxError: missing ] after element list
- jquery ajax 遇到 missing ) after argument list的解决办法
- On-screen Rendering vs. Off-screen Rendering
- (Jquery Ajax Call )Post 一个Form去后台以及AJAX call后DIV重新加载
- WCF Before Call and After Call
- JQuery AJAX Post Not Working On IE8
- Using jQuery to directly call ASP.NET AJAX page methods
- 物料分类账分析
- 360自带--JS开发工具箱
- java-匿名内部类
- to do list
- 足以应付一切的水仙花数,字母交叉问题,数组排序去重复,今天get到一点点,首先一道题莫名其妙地改对了然后明白了自己思路是对的但是不会写代码 还是什么用都没有
- jQuery on: losing attached event after rendering partially by AJAX call
- 第27天 批处理、对象的克隆、内存溢出、设计模式、反射
- python 学习笔记-变量作用域
- mysql命令
- Java并发之基本的线程机制
- 关于android内存优化的几点建议
- python学习笔记-1:pycharm安装以及编写显示“Hello python”
- QT tcp粘包问题
- 大学只待成追忆,只是工作已半年,2016再见