如何跟踪HTML页面上的内容更改页面加载后页面、加载、内容、HTML

2023-09-10 18:02:39 作者:姐、y1然潇洒

我令人头大就这一个我的大脑。

I'm wracking my brain on this one.

HTML文档加载在浏览器中之后,我希望能够监测 如果它的任何内容更改为任何原因的页面。

After an HTML document loads in a browser, I want to be able to monitor the page in case any content on it changes for any reason.

有一个JavaScript函数,我可以跟踪发生了什么 在网页上改变。这应该是无关的HTML页面上的内容类型的

Is there a Javascript function with which I can track 'what has changed' on the webpage. This should be irrespective of the type of content on the HTML page.

我有两个例子给你思考的:

I have two examples for you to ponder on:

假设有两种选择框s1和s2。 该项目列表中的S2取决于选择在S1(页面不 刷新 - 也就是说,S2通过的Ajax或东西加载)。 因此,在HTML页面加载后,我需要得到一个通知,每当S2 填充...

Say in an HTML document there are two select boxes s1 and s2. The items list in s2 depends on selections in s1 (page is not refreshed — that is, s2 is loaded through Ajax or something). So after the HTML page loads I need to get a notification whenever s2 is populated...

说,在HTML页面中,有一个链接,Onclicking将光弹出 DIV与一些文字创建。 我怎样才能捕捉到这种动态弹出的内容?

Say, in an HTML page, there's a link, Onclicking which a light pop-up div is created with some text. How can I capture the content of this dynamic pop-up?

在这一切的讨论中,我不会考虑任何特定的 HTML格式... HTML内容可以是任何东西......我只是需要 保持跟踪,如果在页面加载后的任何内容的修改

In all this discussion, I'm not taking into account any particular format of HTML...the HTML content can be anything...I just need to keep tracking if any content changes after the page loads...

在理想情况下,我需要做到这一点使用JavaScript(客户端 脚本)。 我怎样才能做到这一点?

Ideally I need to achieve this using JavaScript (client-side scripting). How can I achieve this?

推荐答案

如果你正在使用AJAX,你可以设置响应函数来处理增长事件监听系统的家庭。所以后的反应做什么,它需要做的,它可以调用被注册了它的任何方法,通过在响应文本必要时。

If you are using AJAX, you could setup the response function to handle a home grown "event listening" system. So after the response does what it needs to do, it could call any methods that were registered with it, passing in the response text when necessary.

所以从你的例子上面,在练习1,当AJAX从S1返回,这将加载S2,然后调用一个方法说S2发生了变化。在练习2,当新的AJAX返回DIV的内容,加载到DIV后,它调用不同的方法(也可能是同一取决于你试图做什么),并提醒其该div有新的内容。

So from your examples above, in Ex1, when the AJAX returns from S1, it would load S2, then call a method saying S2 had changed. In Ex2, when the new AJAX returns the DIV's contents, after loading it into the DIV, it call a different method (or possibly the same depending on what your trying to do) and alerts it that the DIV has new contents.