未捕获的RangeError:使用innerHTML超出了最大调用堆栈大小

use*_*110 4 javascript innerhtml addeventlistener

我对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;
}
Run Code Online (Sandbox Code Playgroud)

当我用我新修改的字符串替换innerHTML时,LocalMain()函数的最后一行发生异常.此代码中是否存在导致循环或溢出的内容?

epa*_*llo 5

你正在造成无限循环!

您正在元素上侦听DOMSubtreeModified chat_line_list,然后更新附加到该事件的函数内的元素!