使用两种方法在body元素中插入一个按钮:appendChild()方法、innerHTML方法插入一个按钮
,一种是使用appendChild()方法,另外一种是使用innerHTML属性。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function() {

            // document.body.innerHTML = '<input id=“btn” type=“button” value=“按钮”>';
            var oAA = document.createElement("input");        
            document.body.appendChild(oAA);         /*创建节点之后,  需要与组织建立联系*/
            oAA.type = "button";
            oAA.value = "按钮2";
            oAA.id = "btn";
        }
    </script>
</head>
<body>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
相关资源
相似解决方案