javascript动态添加元素
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<script>
function addLiElement() {
var liElement = document.createElement('li');
//liElement.innerHTML = '这是新增的li元素';
var labelElement = document.createElement('label');
var inputElement = document.createElement('input');
labelElement.innerHTML = '单号:'
inputElement.setAttribute('name', 'expressNumber');
liElement.appendChild(labelElement);
liElement.appendChild(inputElement);
var ulElement = document.getElementById('myid');
ulElement.appendChild(liElement);
}
</script>
<ul id="myid">
<li>aa</li>
<li>bb</li>
</ul>
<p>
<button onClick="addLiElement();">动态添加标签</button>
</p>
</body>
</html>
本文地址:https://blog.csdn.net/HardProgrammer/article/details/111057264
上一篇: 历史上司马懿曾装过两次病,分别是在何时?