我之前发过一个问题jQuery 在 IE-8 和 FF-3.5.8 中设置只读属性不一致 https://stackoverflow.com/questions/2381621/jquery-inconsistency-in-setting-readonly-attribute-in-ie-8-and-ff-3-5-8并对答案感到非常满意。
但我确实注意到,如果您动态更新(任何?) DOM 元素,然后查看源代码(使用浏览器的查看源代码),我发现更新后的 DOM 元素属性保留其旧值(更新前)。但是,如果您使用 Firebug/IE Developer 工具栏,它会显示更新的 DOM
Example:http://gutfullofbeer.net/readonly.html http://gutfullofbeer.net/readonly.html
FF3.5-查看页面来源:
<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
方法。使用浏览器查看源代码会给出类似的标记
<input type='text' class='readonly' maxlength='20' value='Blort'>
Firebug 会给出类似的东西
<input type="text" value="Blort" maxlength="20" class="readonly" readonly="">
IE8开发者工具栏:
<input class="readonly" type="text" maxLength="20" readOnly="readonly" value="Blort"/>
所以我的猜测是浏览器(IE8/FF3.5)在 DOM 事件启动之前更早生成 html 源(在我的例子中是 jQuery 的document.ready()
)
有人能告诉我幕后发生了什么吗?