奇怪的问题-也许我漏了什么。
我的代码:
HTML
非常后面的那一行显示了意外的行为。之前使用
我的代码:
HTML
<div id="container">
<span data-foo="initial content">Blabla</span>
</div>
jQuery
console.log($("span").data("foo")); //initial content
console.log($("#container").html()); //<span data-foo="initial content">Blabla</span>
$("span").data("foo", "new content");
console.log($("span").data("foo")); //new content
console.log($("#container").html()); //<span data-foo="initial content">Blabla</span> <----- ?!?!?!?!
非常后面的那一行显示了意外的行为。之前使用
.data("foo", "new content")
进行的修改,通过 .html()
读取内容时不会反映出来。
示例代码:
http://jsfiddle.net/sSZjh/