gpt4 book ai didi

javascript - 如何在文本框中输入数字 Jquery Append

转载 作者:行者123 更新时间:2023-12-01 02:49:50 25 4
gpt4 key购买 nike

我想在文本框中插入数字,但添加行时无法插入,如何插入以追加文本框?

<script>
$('document').ready(function(){
var counter = 0;
$("#addrow").on("click", function () {
counter = $('#myTable tr').length - 3;
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" name="item' + counter + '"/></td>';
cols += '<td><input type="text" name="stock' + counter + '"/></td>';
cols += '<td><input type="button" class="ibtnDel" value="Delete"></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});

$("table.order-list").on("click", ".ibtnDel", function (event) {
$(this).closest("tr").remove();

counter -= 1
$('#addrow').attr('disabled', false).prop('value', "Add Row");
});

$('#stock').val(0);
var nilai1 = $('#stock').val();
$('.angka').click(function(){
if($('#stock').val()==0){
nilai1 ='';
}
nilai1 += $(this).val();
$('#stock').val(nilai1);
});
});
</script>

可以帮助我吗?欲了解更多详细信息,请点击 preview

最佳答案

选择任何字段,无论是否动态添加,您都可以在选定的文本字段中添加值

var counter = 0;
var sItem;
$(document).on('click', '.dumy', function(){
sItem = $(this);

});
$("#addrow").on("click", function () {
counter = $('#myTable tr').length - 3;
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" name="item' + counter + '"/></td>';
cols += '<td><input type="text" class="dumy" name="stock' + counter + '" id="stock' + counter + '"/></td>';
cols += '<td><input type="button" class="ibtnDel" value="Delete"></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});

$("table.order-list").on("click", ".ibtnDel", function (event) {
$(this).closest("tr").remove();

counter -= 1
$('#addrow').attr('disabled', false).prop('value', "Add Row");
});

$('#stock').val(0);

$('.angka').click(function(){
var nilai1 = $(sItem).val();
if($(sItem).val() == 0){
nilai1 ='';
}
nilai1 += $(this).val();
$(sItem).val(nilai1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div>
<input type="button" class="angka" value="1" id="satu">
<input type="button" class="angka" value="2" id="dua">
<input type="button" class="angka" value="3" id="tiga">
</div>
<table id="myTable" class="order-list">
<thead>
<tr>
<td colspan="5" style="text-align: left;">
<input type="button" id="addrow" value="Add Row" />
</td>
</tr>
<tr>
<td>Item</td>
<td>Stock</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="item0" id="item" />
</td>
<td>
<input type="text" name="stock0" class="dumy" id="stock" />
</td>
<td><a class="deleteRow"></a>

</td>
</tr>
</tbody>
</table>

关于javascript - 如何在文本框中输入数字 Jquery Append,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47039916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com