我有一个试图更新属性的 HTML 字符串,但我似乎看不到更改。这是一个简化的示例:
var source = '<html><head></head><body><img src="abc" /><img src="abc" /></body></html>';
$(source).filter('img').each(function () {
$(this).attr('src', '123');
});
// At this point if I look at source in a debugger
// I'd expect to see the src attributes as all being
// '123', but I still see them all as 'abc'.
应该如何编写,以便源随更改而更新?