SetAttribute函数在Chrome浏览器中无法正常工作

时间:2019-11-04 03:27:46

标签: javascript

从我的一个类中获得了一个示例,该示例动态对齐了一个“ div”元素,但由于某种原因,它似乎在Chrome中无法正常工作。教授无法给我确切的原因。在IE中工作正常。

any cpu

1 个答案:

答案 0 :(得分:0)

尝试一下

<!DOCTYPE html>
<html>
<head>
<title>Example: Getting Attributes</title>
</head>

<body>
<h3>CIW JavaScript Specialist</h3>
<hr>
<div id="SetDiv" special_attribute="CIW rules!" align="left">
<p><h3>What are the attributes of this div tag?</h3></p>
</div>
    <input type="button" value="Click Me to move left!" onclick="moveMe('left')">
     <input type="button" value="Click Me to move center!" onclick="moveMe('center')">
      <input type="button" value="Click Me to move right!" onclick="moveMe('right')">
    <p><h3>Please click the button now</h3></p>
    <script type="text/javascript">

        function moveMe(value) {
          document.getElementById("SetDiv").setAttribute("align",value);
        }


    </script>
</body>
</html>

基本上,您是在更改dom更改反映到页面之前进行更改。

相关问题