站长资讯网
最全最丰富的资讯网站

JS中行内style怎么写?

行内style的写法为:1、对复合属性的写法是去掉中间的“—”,并将第二个单词大写,代码为【alert(box.style.color)】;2、float是关键字有特殊写法,代码为【alert(box.style.float)】。

JS中行内style怎么写?

JS中行内style的写法为:

1、访问元素样式1, stye属性只对行内样式有用

var box = document.getElementById("box");

2、对复合属性的写法是去掉中间的“—”,并将第二个单词大写。

 // alert(box.style.color);     // alert(box.style.fontSize);

3、float是关键字,因此最好不要这样写    

 //alert(box.style.float);

4、对float属性ie和非ie有差异:

 // alert(box.style.cssFloat); //非ie     // alert(box.style.styleFloat); //IE专用

5、给float赋值,且兼容所有浏览器  

 // typeof box.style.cssFloat !="undefined"?box.style.cssFloat = "right":box.style.styleFloat ="right";

相关学习推荐:javascript视频教程

赞(0)
分享到: 更多 (0)