您的位置:首页 > Web前端 > JavaScript

js增加行

2015-12-07 17:36 585 查看
js增加行,自动增加每行id

<ul id="fwtable" class="items">
<li>
定义一个隐藏控件记录行数
<input type="hidden" name="jsfw" value="new1" />
<label class="itm"><strong>*</strong>附件上传:</label><span class="item"><asp:FileUpload ID="FileAttach1" runat="server" /></span>
</li>
</ul>

当点击增加行时拼接html:

function addRow() {
//定义html
var gshtml = "";
//最后的数值,id
var lastIndex;
if ($("input:hidden[name='jsfw']").size() > 0) {
var lastnew = $("input:hidden[name='jsfw']:last").val();
lastIndex = parseInt(lastnew.substr(3)) + 1;
} else {
lastIndex = 1;
}
//拼接html
gshtml += '<li id=' + (lastIndex + 5) + '><input type="hidden" name="jsfw" value="new' + lastIndex + '" /><label class="itm"><strong></strong></label><span class="item"><input id="FileAttach' + lastIndex + '" type="file" /><button onclick="del(' + (lastIndex + 5) + ');"> - </button></span></li>';
//将拼接的html加到容器,例子中为ul
$("#fwtable").append(gshtml);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: