【发布时间】:2016-05-06 13:26:22
【问题描述】:
让我解释一下
我有一个包含弹出窗口元素的 DOM。 HTML 看起来像:
<div class='editor'></div>
<div class='editor'></div>
我正在开发 Chrome 扩展程序,它必须按 editor 类查找所有元素,如果找不到某些文本,请添加它。
到目前为止,它正在工作。 DIV 包含textarea。如果一个人删除了文本,实际上会发生什么,它会再次添加。发生这种情况是因为我正在使用计时器来嗅探是否弹出了新窗口。
我是否可以确定某个文本已添加到 DIV 中?元素是否有一些内部 ID?
PS:当我写这个问题时,我想到了一个事情,我遍历所有元素都有 editor 类并将唯一 ID 分配为 editor1,editor2..
不知道有没有其他方法?
谢谢
更新
带有类名editor的jQuery嗅探元素的Chrome扩展,如果找到或找到它们visible it inserts text, sayHello World. IfHello Worldalready there, it does not end. So far it's working fine. Issue is what if user manually removed **Hello World**, the code which is running undersetinterval`块再次添加它。我不希望第二次添加,因为代码不应在已添加的元素中添加 Hello World。
【问题讨论】:
-
无法理解问题:(
-
你能解释一下这个声明
if it does not find certain text, add it.吗?然后....So far it's working.- 什么工作?在 jsfiddle 中分享一些示例并进行解释。 -
@JohnR 解释已添加。
标签: javascript jquery google-chrome-extension