JS动态添加标签

别来无恙 提交于 2019-11-27 12:46:48

 JS动态添加标签

如代码示例,使用jquery,动态的增加标签:

function addDiv(serial) {
        //最外层父div
        var div = document.createElement("div");  
        document.getElementById("form").appendChild(div);


        var childDiv1 = document.createElement("div");
        document.getElementById(div.id).appendChild(childDiv1);

        var label1 = document.createElement("label");
        document.getElementById(childDiv1.id).appendChild(label1);

        var childDiv1_1 = document.createElement("div");
        document.getElementById(childDiv1.id).appendChild(childDiv1_1);

        var input1 = document.createElement("input");
        document.getElementById(childDiv1_1.id).appendChild(input1);

    }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!