javascript无法直接通过document.getElementById([id]).style.[属性值]去获取html标签里的class属性里的值,探究过程如下:
一、在标签里直接加入style
function getWidth() {
var obj = document.getElementById("div1");
alert(obj.style.width);
}
执行结果如下图:正常

二、仅在标签时加入一个class,不加style
<style type="text/css">
.dicCss{width:200px; height:200px; border:1px solid #f00;}
</style>
function getWidth() {
var obj = document.getElementById("div2");
alert(obj.style.width);
}
执行结果如下图:没有得到预期的值

三、重写javascript方法
function getClassAttrValue(obj, attribute) {
return obj.currentStyle ? obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj, false)[attribute];
}
function getWidth() {
var obj = document.getElementById("div2");
alert(getClassAttrValue(obj, "width"));
}
执行结果如下图:正常

| 昵称: | |
| 邮件: | |
| 链接: | |
评论列表
回复:你好,不知你指的动态金鱼是什么?是不是那个Falsh?如果是它的话,你直接下载就可以了http://www.fetso.cn/themes/micro/images/bg.swf
Recole: 谢谢