javascript setAttribute样式 [英] javascript setAttribute style

查看:79
本文介绍了javascript setAttribute样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道以下两个javascript / css代码如何产生不同的结果:

I don't get how the two following javascript/css codes can produces different result:

1st:

prev.setAttribute('style', 'position:absolute;left:-70px;opacity:0.4;border-radius: 150px;-webkit-border-radius: 150px;-moz-border-radius: 150px;');

第二名:

            prev.setAttribute('style', 'opacity:0.4;border-radius: 150px;-webkit-border-radius: 150px;-moz-border-radius: 150px;');
            prev.setAttribute('height', size);
            prev.setAttribute('width', size);
            prev.setAttribute('id', 'thumb'+i);
            prev.setAttribute('position', 'absolute');
            prev.setAttribute('left', '-70px');

在第二个,位置和左边完全被忽略。拥有2行代码但没有代码的结果是一样的。

in the 2nd one, position and left are completely ignored. The result are the same for having the 2 lines of codes and not having them.

只有当我把 prev.style.left ,与位置相同的东西。但是setAttribute适用于高度和宽度。我真的需要知道为什么

It only works if I put prev.style.left, the same thing with position. However setAttribute works for height and width. I really need to know why

推荐答案

position left 不是属性,它们是样式。

position and left are not attributes, they are styles.

width height id 可以用作属性或样式,这就是他们在第二个例子中工作的原因。

width, height and id can be used as attributes or styles, which is why they work in your second example.

这篇关于javascript setAttribute样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆