本文介绍了jQuery中的太多递归错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码:

给我和太多递归"的错误

given me and error of "too much recursion"

有人可能认为我应该将处理程序附加到crosslink元素上.我试过了,但是我无法使它正常工作,因为在创建交叉链接类元素之前先加载DOM.我需要做些什么来解决此问题,或者您对实现我想做的事情应该做些什么有更好的了解?

one might think that I should just attach a handler to the crosslink element. i tried this, but I couldn't get it to work because the DOM loads before the cross-link class elements are created. what do I need to do to fix this or do you have a better idea of what I should do to implement what I'm trying to do?

如果您想亲自查看错误,请访问eataustineat.com/testfolder/在搜索字段中输入"d"选择全能的狗(这是您应该注意到太多递归错误"的地方它将div移到左侧,但是这样做会非常麻烦.

if you want to see the error for yourself, do to eataustineat.com/testfolder/type in a 'd' in the search fieldselect dog almighty (this is where you should notice the "too much recursion error"it will move the div to the left, but it will do so very buggily.

推荐答案

您可以使用livedelegate为以后创建的元素添加侦听器:

You can use live or delegate to add listeners for elements that are created later:

$("a.cross-link").live("click", function()
{
   $('a[href=#2]').trigger('click');
   window.location.hash = "#2";
});

但是,单击不会触发转到URL的默认事件,因此您需要手动进行操作.

However, click does not trigger the default event of going to the URL, so you need to do that manually.

这篇关于jQuery中的太多递归错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:49
查看更多