【发布时间】:2017-07-23 00:20:48
【问题描述】:
我想用下面的代码更改我的正文 html 中的一些文本。替换工作正常,但之后似乎卡住了,无法退出功能,因此我的脚本的下一部分无法执行。
点击 .another-button 后什么都不会发生。我认为问题在于更改 body.innerHTML 的行,因为当我删除此行时一切正常。
$(".do-replace-button").on("click", function () {
//some different code
document.body.innerHTML = document.body.innerHTML.replace(regExp, newWord);
}
$(".another-button").on("click", function (event) {
//some code that won't execute
}
【问题讨论】:
-
您在正文中使用
innerHTML,所以当第一个事件执行时,所有其他处理程序都将被删除。 Manipulating innerHTML removes the event handler of a child element?
标签: javascript jquery innerhtml