<p id="demo">单击按钮创建button元素</p><button onclick="myFunction()" value="ud">点我</button><script>let count = 0;function myFunction() {if (count != 0) return;var btn = document.createElement("BUTTON");document.body.appendChild(btn);btn.value = "hhh";var ipt = document.createElement("INPUT");ipt.type = "button";document.body.appendChild(ipt);ipt.value = "hhh";count++;};</script>
<input type = "button">
和<button></button>
的区别:前者在网页上显示的是value的属性值;后者在网页显示的是开始标签和结束标签之间的。前者用value来获取或者改变网页上显示的东西,后者用innerHTML来获取或改变网页上显示的东西。