我有一个html表,我可以在其中动态添加和删除行。为了避免进一步混淆,我希望每行第一个条目的占位符成为所述行的索引。
一个小例子:
<!DOCTYPE html>
<html>
<body>
<script src="https://code.jquery.com/jquery-1.12.1.js" integrity="sha256-VuhDpmsr9xiKwvTIHfYWCIQ84US9WqZsLfR4P7qF6O8=" crossorigin="anonymous"></script>
<script>
window.SomeDeleteRowFunction = function SomeDeleteRowFunction(o) {
var p=o.parentNode.parentNode;
p.parentNode.removeChild(p);
}
$('document').ready(function() {
$('.add_another').click(function() {
$("#tbl").append('<tr><td><input type="text" class="txtbox" value="" placeholder=x.rowIndex/> </td></tr>');
});
})</script>
<table id="tbl">
<tr>
</tr>
<tr>
<td><input type="text" name="links" placeholder=x.rowIndex /></td>
<td><input type="button" value="Delete Row" onclick="SomeDeleteRowFunction(this)"/></td>
</tr>
</table>
<input type="submit" class="button add_another" value="Add another line"/>
</body>
</html>
在这个例子中,我希望用当前行索引替换x.rowindex。
有办法做到这一点吗?
谢谢!
答案 0 :(得分:1)
<!DOCTYPE html>
<html>
<body>
<script src="https://code.jquery.com/jquery-1.12.1.js" integrity="sha256-VuhDpmsr9xiKwvTIHfYWCIQ84US9WqZsLfR4P7qF6O8=" crossorigin="anonymous"></script>
<table id="tbl">
<tr>
<td><input type="text" name="links" placeholder=1 /></td>
<td><input type="button" value="Delete Row" onclick="SomeDeleteRowFunction(this)" /></td>
</tr>
</table>
<input type="submit" class="button add_another" value="Add another line" />
</body>
</html>
{{1}}