<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>添加按钮</title> <style> .box{ width: 50px; height:50px; border:1px solid #000; } </style> </head> <body> <div class="wrap box">111</div> <input type="text" id="addvalue"> <button type="button">添加</button> </body> <script> var add=document.getElementsByClassName("add")[0]; add.addEventListener("click",function(e){ e.preventDefault(); var divs=document.createElement("div"); var addValue=document.getElementById("addvalue").value; var textDiv=document.createTextNode(addValue); divs.appendChild(textDiv); divs.setAttribute("class","box"); // 怎么显示在class:wrap元素的前面 或者后面 还有里面? }) </script> </html>
相关分类