JavaScript实现js添加dom元素(以下拉框为例子)

效果图:

也可以根据自己的需要更改下拉框的值
在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body> 
		 
		<input type="button" id="" value="添加" onclick="add()" />
		<div id="sel">
			
		</div>
		<script type="text/javascript">
			function add(){
				var select=document.createElement("select");
				var op1=document.createElement("option");
				op1.value="1801";
				op1.innerText="移动互联";
				select.appendChild(op1);
				document.getElementById("sel").appendChild(select)
			}
		</script>

		
	</body>
</html>

原文地址:https://www.cnblogs.com/a1439775520/p/13046977.html