首页 > 解决方案 > 如何在 html 表中动态创建带有 div 类的输入元素?

问题描述

我可以在 html 表中动态创建输入元素,但我需要创建由使用input包围的动态元素divjavascript

像这样,

<td>
    <div class="autocomplete">
    <input style="height: 30px !important; width:400px;" class="form-control 
     rightalign" id="productname0">
     </div>
</td>

标签: javascripthtml

解决方案


你的问题不是很清楚。尝试类似的事情:

var i = document.createElement("INPUT");
i.type="text";
i.setAttribute("style","height: 30px !important; width:400px;");
i.className="form-control rightalign";
i.id="productname0";  

Array.prototype.slice.apply( document.getElementsByClassName("autocomplete")).map(function(div, j){
    div.appendChild(i.cloneNode(true));
});

推荐阅读