我对 Javascript 不是很有经验,但我遇到了一个我无法理解的问题。我的代码很简单:
document.getElementById ('chat_line_list').addEventListener ("DOMSubtreeModified", LocalMain, false);
function LocalMain ()
{
var chatList = document.getElementById('chat_line_list').lastChild.lastElementChild.innerHTML;
chatList = chatList.replace('InfoThump', '<span class="newemo-1 emoticon"></span>');
chatList = chatList.replace('MuskMelon', '<span class="newemo-2 emoticon"></span>');
chatList = chatList.replace('PoisonApple', '<span class="newemo-3 emoticon"></span>');
chatList = chatList.replace('PoisonBanana', '<span class="newemo-4 emoticon"></span>');
chatList = chatList.replace('PoisonWatermelon', '<span class="newemo-5 emoticon"></span>');
chatList = chatList.replace('PoisonGrape', '<span class="newemo-6 emoticon"></span>');
chatList = chatList.replace('NotNippy', '<span class="newemo-7 emoticon"></span>');
document.getElementById('chat_line_list').lastChild.lastElementChild.innerHTML = chatList;
}
当我用新修改的字符串替换 innerHTML 时,异常发生在 LocalMain() 函数的最后一行。此代码中是否存在导致循环或溢出的内容?
最佳答案
你正在造成无限循环!
您正在监听元素 chat_line_list
上的 DOMSubtreeModified,然后您在附加到该事件的函数中更新该元素!
关于javascript - 未捕获的范围错误 : Maximum call stack size exceeded with innerHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16466691/