在项目中经常遇到需要动态添加DOM,下面来讲解一下如何动态生成:
function addDomTest(){
var vIndex = jQuery("#Question-List").find("tr").length;
var vQuestionRow = [];
vQuestionRow.push("<tr id='tr"+(vIndex+1)+"' index="+vIndex+">");
vQuestionRow.push("<td style='text-align:center'>"); //序号
vQuestionRow.push("<input type='hidden' name='riskAuditQuestionDTOs["+vIndex+"].id' value=''/>");
vQuestionRow.push("<span>"+(vIndex+1)+"</span>");
vQuestionRow.push("</td>");
vQuestionRow.push("</tr>");
jQuery("#Question-List").append(vQuestionRow.join(""));
}
本文介绍了一个使用jQuery实现动态添加DOM元素的方法。通过获取当前表格行数,构造新的表格行并将其添加到指定ID的元素中。
1547

被折叠的 条评论
为什么被折叠?



