Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IE7:如何设置;“类”;javascript中动态创建的元素的属性?_Javascript_Css_Class_Internet Explorer 7 - Fatal编程技术网

IE7:如何设置;“类”;javascript中动态创建的元素的属性?

IE7:如何设置;“类”;javascript中动态创建的元素的属性?,javascript,css,class,internet-explorer-7,Javascript,Css,Class,Internet Explorer 7,看来: var img = document.createElement("img"); img.setAttribute("class", "check"); 在IE7中不起作用,即该类在css中指定的样式不适用。它在IE8、FF等中运行良好。是否有办法在IE7中设置类,或者我必须执行以下操作: img.style.border = .... 谢谢我相信您需要使用: img.className = "check"; 我认为您需要使用: img.className = "check";

看来:

var img = document.createElement("img");
img.setAttribute("class", "check");
在IE7中不起作用,即该类在css中指定的样式不适用。它在IE8、FF等中运行良好。是否有办法在IE7中设置类,或者我必须执行以下操作:

img.style.border = .... 

谢谢

我相信您需要使用:

img.className = "check";

我认为您需要使用:

img.className = "check";
只是:

当您有时尝试使用“setAttribute()”时,Internet Explorer可能会非常不高兴。我没有运行虚拟机,但如果您已经下定决心使用“setAttribute()”,那么您可以尝试:

img.setAttribute("className", "check");
但我不知道这是否行得通。

只要:

当您有时尝试使用“setAttribute()”时,Internet Explorer可能会非常不高兴。我没有运行虚拟机,但如果您已经下定决心使用“setAttribute()”,那么您可以尝试:

img.setAttribute("className", "check");
但我不知道那会起作用