ActionLink执行多次 [英] ActionLink executing multiple times
问题描述
我有一个Ajax操作链接,该链接将div部分添加到div.
I have an ajax action link which is appending a partial to a div.
$('#hypNewCriteria').click(newClick);
...
var newClick = (function ()
{
console.log('newClick');
$.ajax(this.href, {
success: function (result)
{
...
}
}
在第一页加载和返回的每个部分上,我(可能是不必要的)正在通过document.ready
On the first page load and on every partial that is returned I am (probably unnecessarily), am executing via a document.ready
$('#hypNewCriteria').click(newClick);
...随后点击操作链接;每次返回的局部视图的数量增加1.单击7次后,将返回8个部分.我希望只添加1个部分.
... subsequent clicks on the actionlink; the number of partial views returned increases by 1 each time. After 7 clicks, it returns 8 partials. I expect only 1 partial to append.
我怀疑.click(newClick)事件正在追加.是否可以设置一个单击事件或在设置另一个事件之前清除该事件?
I suspect the .click(newClick) event is appending. Is there a way to set just one click event or clear the event before I set another?
推荐答案
您可以使用jQuery的unbind()方法取消绑定事件.
You can use jQuery's unbind() method to unbind events.
我还将研究live()jQuery方法.这会将事件绑定到添加到页面上的所有当前和将来元素,对于加载部分页面或添加需要始终添加事件的项目的页面很有用.
I would also look into the live() jQuery method. This binds an event to all current and future elements that are added to a page, useful for pages that load partials or add items that require events to be added all the time.
这篇关于ActionLink执行多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!