<script>
function addRequire() {
addRow('#tBasRfqPublicRequireParamsids', purchaseSpecificationRowIdx, qwer);
purchaseSpecificationRowIdx = purchaseSpecificationRowIdx + 1;
}
function addRow(list, idx, tpl, row) {
console.log("list"+list);
console.log("idx"+idx);
console.log("tpl"+tpl);
$(list).append(Mustache.render(tpl, {
idx: idx, delBtn: true, row: row
}));
$(list + idx).find("select").each(function () {
$(this).val($(this).attr("data-value"));
});
$(list + idx).find("input[type='checkbox'], input[type='radio']").each(function () {
var ss = $(this).attr("data-value").split(',');
for (var i = 0; i < ss.length; i++) {
if ($(this).val() == ss[i]) {
$(this).attr("checked", "checked");
}
}
});
}
function delRow(obj, prefix) {
var id = $(prefix + "_id");
var delFlag = $(prefix + "_delFlag");
if (id.val() == "") {
$(obj).parent().parent().remove();
} else if (delFlag.val() == "0") {
delFlag.val("1");
$(obj).html("÷").attr("title", "撤销删除");
$(obj).parent().parent().addClass("error");
} else if (delFlag.val() == "1") {
delFlag.val("0");
$(obj).html("×").attr("title", "删除");
$(obj).parent().parent().removeClass("error");
}
}
</script>
<script type="text/template" id="qwer">//<!--
<tr id="tBasRfqPublicRequireParamsids{{idx}}">
<input id="tBasRfqPublicRequireParamsids{{idx}}_id" name="tBasRfqPublicRequireParamsids[{{idx}}].id" type="hidden" value="{{row.id}}"/>
<input id="tBasRfqPublicRequireParamsids{{idx}}_delFlag" name="tBasRfqPublicRequireParamsids[{{idx}}].delFlag" type="hidden" value="0"/>
<td>
<input id="tBasRfqPublicRequireParamsids{{idx}}_requireName" name="tBasRfqPublicRequireParamsids[{{idx}}].requireName" type="text" value="{{row.requireName}}" maxlength="64" class="input-small required"/>
</td>
<td>
<input id="tBasRfqPublicRequireParamsids{{idx}}_requireContent" name="tBasRfqPublicRequireParamsids[{{idx}}].requireContent" type="text" value="{{row.requireContent}}" maxlength="64" class="input-small required"/>
</td>
//-->
</script>
<script type="text/javascript">
var purchaseSpecificationRowIdx = 0;
var qwer = $("#qwer").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g, "");
$(document).ready(function () {
var data = ${fns:toJson(tBasRfqParamsModelname.tBasRfqPublicRequireParamsids)};
console.log(data);
for (var i = 0; i < data.length; i++) {
addRow('#tBasRfqPublicRequireParamsids', purchaseSpecificationRowIdx, qwer, data[i]);
purchaseSpecificationRowIdx = purchaseSpecificationRowIdx + 1;
}
});
</script>
贴出代码为jeesite中自动生成的一对多点击按钮动态添加表的行数,代码中标红的代码必须放在最下面才能实现功能。坑爹啊