我有一个 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 替换为当前行索引。
有没有办法做到这一点?
谢谢!
window.SomeDeleteRowFunction = function SomeDeleteRowFunction(o) {
var p = o.parentNode.parentNode;
p.parentNode.removeChild(p);
$('#tbl tr').each(function(i) {
$(this).find('input').eq(0).attr("placeholder", i+1);
});
}
$('document').ready(function() {
$('.add_another').click(function() {
$("#tbl").append('<tr><td><input type="text" class="txtbox" value="" placeholder="' + ($('#tbl tr').length + 1) + '"/></td><td><input type="button" value="Delete Row" onclick="SomeDeleteRowFunction(this)" /></td></tr>');
});
});
<!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>
Salve sono Franceschi David mi è stato indicato di rivolgermi a voi per un problema ci sono due giochi che ho scaricato e portato avanti per raggiungere la ricompensa Uber Eats(1,125-TR_PLACEHOLDER): 客户ID:37823 UID:15d818cf-36c2-47ef-bf41-deb4ba314e79 日期:3/10/23 上午 11:59 数量: 270,000 感觉 状态:未完成
e tinaba (875 TR_PLACEHOLDER): 客户ID:35195 UID:15d818cf-36c2-47ef-bf41-deb4ba314e79 日期:3/7/23 下午 2:07 数量: 210,000 感觉 状态:未完成
ma non ancora ricevuto niente ,mi potete aiutare 亲切的敬礼 弗朗切斯基大卫