为什么HTML源代码时,DOM是动态更新不会改变 [英] Why would html source not change when the DOM is updated dynamically
问题描述
我贴过一个问题前面<一个href=\"http://stackoverflow.com/questions/2381621/jquery-inconsistency-in-setting-readonly-attribute-in-ie-8-and-ff-3-5-8\">http://stackoverflow.com/questions/2381621/jquery-inconsistency-in-setting-readonly-attribute-in-ie-8-and-ff-3-5-8并且是与答案非常高兴。
I had posted one question earlier http://stackoverflow.com/questions/2381621/jquery-inconsistency-in-setting-readonly-attribute-in-ie-8-and-ff-3-5-8 and was quite happy with the answer.
但我没有注意到,如果你更新(任意?)DOM元素动态,然后查看源(使用浏览器的查看源文件)我找到更新的DOM元素属性保留其旧的价值(更新之前)。但是,如果你使用Firebug / IE开发工具栏,它会显示更新的DOM
But I did notice that if you update (any??) DOM elements dynamically, then view source (using browser's view source) I find the the updated DOM element attribute retains its older value(before update). However, if you use Firebug/IE Developer toolbar, it displays the updated DOM
例如:http://gutfullofbeer.net/readonly.html
Example:http://gutfullofbeer.net/readonly.html
FF3.5-查看页面源代码:
FF3.5-View page Source:
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js' type='text/javascript'></script>
<script>
$(function() {
$('input.readonly').attr('readonly', true);//set input with CSS class readonly to readonly
});
</script>
</head>
<body>
<input type='text' class='readonly' maxlength='20' value='Blort'>This one is read-only<br>
<input type='text' maxlength='20' value='Fish'>This one is not read-only<br>
</body>
</html>
下面第一个文本框设置在jQuery的的document.ready
方法为只读。查看与浏览器源会给像一个标记
Here the first text box is set to readonly in jQuery's document.ready
method. Viewing the source with browser would give a markup like
<input type='text' class='readonly' maxlength='20' value='Blort'>
和萤火虫会给像
<input type="text" value="Blort" maxlength="20" class="readonly" readonly="">
IE8开发工具栏:
IE8 Developer toolbar:
&LT;输入类=只读类型=文本最大长度=20readOnly的=只读值=Blort/&GT;
所以我的猜测是,浏览器(IE8 / FF3.5)早得多生成HTML源之前DOM事件踢(在我的情况下,它是jQuery的的document.ready()
)
So my guess is that the browser (IE8/FF3.5) generates the html source much earlier before DOM events kick in (in my case it is jQuery's document.ready()
)
有人能告诉我发生了什么幕后?
Can someone tell me whats happening behind the scene ?
推荐答案
查看源代码是下载到浏览器的源代码。会发生什么事在内存中没有在源得到更新。
The view source is the source downloaded to the browser. What happens in memory doesn't get updated in the source.
这篇关于为什么HTML源代码时,DOM是动态更新不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!