【发布时间】:2014-09-01 11:18:26
【问题描述】:
我正在阅读《jQuery Pocket Reference》一书,O'Reilly,2011 年。
第 15 页上写着:
'例如调用 attr("css", {backgroundColor:"gray"}) 与调用 css({backgroundColor:"gray"}) 是一样的。'
但我无法使 attr(“css”, { }) 工作。我的测试代码:http://jsfiddle.net/4UMN3/4/
$(function() {
$("#btnChangeColor").click(function () {
$("#spanText").attr("css", { backgroundColor: "gray" });
});
});
css() 方法工作正常,http://jsfiddle.net/4UMN3/5/
【问题讨论】:
-
the docs 中对此一无所知。可能是error in the book。
-
如果您有
.css(),为什么还需要使用.attr()? -
@Blazemonger - 很好的发现,就是这个。作者搞砸了。
-
是的,这本书肯定是错的