如何将.rotatable
类分配给以下img元素而不是('src', 'rotate.png')
?
$(document.createElement('img')).attr('src', 'rotate.png')
的CSS:
.rotatable {
cursor: move;
background-image: url(rotate.png);
}
答案 0 :(得分:0)
由于您使用的是jQuery,因此根本没有理由使用document.createElement()
:
var img = $("<img/>", {
"class": "rotatable",
"src": "rotate.png"
});
答案 1 :(得分:0)
如果您只是尝试使用jQuery添加类,则可以:
$('img').addClass('rotatable');