js:
function insertTag(num){
var address=document.getElementById("tag");
var i=address.childNodes.length;
if(i>num){
alert('最多可以输入4个标签!');
return;
}
var addressOld = document.getElementById("tagTemplate");
var addressNew=document.createElement("div");
addressNew=addressOld.cloneNode(true);
addressNew.style.display="inline";
addressNew.id="tag" + i;
address.appendChild(addressNew);
}
页面:
<#assign i=0>
<#list video?if_exists.tagList?if_exists as tgl>
<#assign i = i + 1>
<tr>
<td>
标签:<input type="text" id="tags" name="videoVO.tags" value="${tgl.name}"/>
</td>
</tr>
</#list>
<#assign sum = 4>
<#assign sum = sum - i>
<tr>
<td>
<div id="tagTemplate" name="tagTemplate" style="display: none;">
标签:<input type="text" name="videoVO.tags"/>
<input type="button" value="删除" οnclick="javascript:this.parentNode.parentNode.removeChild(this.parentNode);"/>
<br/>
</div>
<div id="tag" name="tag" >
<div><a href="javascript:insertTag(${sum});" >增加一个标签</a></div>
</div>
</td>
</tr>