html页面的内容由jQuery改变,但“查看源代码”不反映这些变化 [英] Content of html page changed by jQuery but "View Source" don't reflect the changes

查看:92
本文介绍了html页面的内容由jQuery改变,但“查看源代码”不反映这些变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery: v1.7.1

你好家伙,
我改变了jQuery的img属性像这样:



$ $ $ $ $$ $ $ $ $ $ $ Spring.jpg,alt:spring});
});

更改反映在浏览器中,但是,
1) 查看源代码没有改变(这是原始的html),这是由js改变的,为什么?
像这样:

 < a href =images / Grass.jpg> 
< img src =images / Grass.jpgalt =image/> < / A>

2)当我从Firebug进行检查时,它显示了jquery所做的更改?

 < a href =images / Grass.jpg> 
< img alt =springsrc =images / Spring.jpg> < / A>

这里发生了什么?

Q )是否对内存中的DOM做了更改?和萤火虫如何显示它?

解决方案

源代码从不 改变。当你的查看源代码刚刚向你显示了浏览器从服务器接收到的内容时。



它是您操纵的 DOM (文档对象模型),而不是HTML。



初始DOM状态是源HTML的表示形式,但它不与源HTML永久链接。 Javascript改变了DOM而不是HTML。请参阅此处了解DOM的完整说明: http://www.w3.org/ TR / DOM-Level-2-Core / introduction.html


文档对象模型(DOM)是一个应用程序编程
接口(API)用于有效的HTML和格式良好的XML文档。它
定义了文档的逻辑结构和文档被
访问和操作的方式。

标题DOM不是什么的标题下的相关引用:


文档对象模型不是持久化对象的方法XML或
HTML。
DOM指定了如何将XML和HTML文档表示为对象
,以便它们可以在面向对象的程序中使用,而不是指定如何用XML表示对象。




Firebug(和其他开发人员工具框架)同样向您显示DOM的当前状态(因为这是动态的)。这就是为什么看到Firebug的变化,但不是在源代码视图中。


jQuery: v1.7.1
Hello guys,
I changed the img attributes from jQuery Like this:

        $("document").ready(function () {
        $("img").attr({ src: "images/Spring.jpg", alt: "spring" });
    });

Changes are reflected in the browser but,
1) when I checked the "view source code" there were no changes(it was original html) which were changed by the js ,why? Like this:

    <a href="images/Grass.jpg">
    <img src="images/Grass.jpg" alt="image"/> </a>

2) And when I checked from Firebug it showed the changes made by jquery ?

<a href="images/Grass.jpg">
<img alt="spring" src="images/Spring.jpg"> </a>

Whats going on here ?
Q) Are the changes made to DOM done in memory ? and How can firebug show it ?

解决方案

The source code never changes. When you "view source" that just shows you exactly what the browser received from the server.

It is the DOM (Document Object Model) that you are manipulating, not the HTML.

The initial DOM state is a representation of the source HTML, but it is not permanently linked with the source HTML. Javascript changes the DOM but not the HTML. See here for a full explanation of the DOM: http://www.w3.org/TR/DOM-Level-2-Core/introduction.html

The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.

And a relevant quote from the page under the heading "What the DOM is not":

The Document Object Model is not a way of persisting objects to XML or HTML. Instead of specifying how objects may be represented in XML, the DOM specifies how XML and HTML documents are represented as objects, so that they may be used in object oriented programs.

Firebug (and other developer tool frameworks), similarly, show you the current state of the DOM (because that's what is dynamic). That's why see the change in Firebug, but not in the source code view.

这篇关于html页面的内容由jQuery改变,但“查看源代码”不反映这些变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆