0
点赞
收藏
分享

微信扫一扫

增删改节点

夏侯居坤叶叔尘 2022-08-24 阅读 49


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>增删改节点</title>
<script>
window.οnlοad=function () {
var bodyNode=document.getElementsByTagName('body')[0];
alert(bodyNode);

var divNode=document.createElement("div");/*创建一个元素*/
/*设置属性名和值*/
divNode.setAttribute("style",'width:300px;height:300px;background:red');
bodyNode.appendChild(divNode); //在元素添加一个元素

var inputNode=document.createElement('input');
var buttonNode=document.createElement('button');
divNode.appendChild(inputNode);
divNode.appendChild(buttonNode);

buttonNode.parentNode.removeChild(buttonNode);

var inputNameNode=document.getElementsByName('username')[0];
var name=inputNameNode.getAttribute('name');/*获取元素的属性值*/
alert(name);

}
</script>
</head>

<body>

<input type="text" name="username">

</body>

</html>

举报

相关推荐

0 条评论