gpt4 book ai didi

javascript - 如何使用jquery add函数添加动态数据?

转载 作者:行者123 更新时间:2023-11-28 05:09:52 25 4
gpt4 key购买 nike

我有这段代码,我使用 jQuery 代码来复制表,原始表可以正常使用 php fetch 查询,但是如果我向其中添加 php 代码,复制过程将不起作用,但如果删除了 php 代码它有效。

  <form action="" method="post" name="addusers" id="addusers">
<div class="felements"><select name="proname" type="text" required class="tfield2" id="proname">
<option id="0">-- Select Provider --</option>
<?php $prov = $con->query("SELECT * FROM providers"); while ($vall = mysqli_fetch_array($prov)){ ?>

<option id="<?php echo $vall ['ID'];?>">
<?php echo $vall ['provname']?>
</option>
<?php } ?>
</select></div>

<div class="felements"><input name="invodate" type="text" required class="tfield" id="invodate" placeholder="Invoice Date"/>
</div>
<div class="felements"><input name="Save" type="submit" class="button" value="Save" style="width: 91%;"></div>

<table class="table table-borderd table-hover felements">
<thead>
<th>Company Name</th>
<th>Claimed Amount</th>
<th>Exchange Rate</th>
<th>Claimed Amount (LYD)</th>
<th>Insurance Type</th>
<th><input type="button" value="+" id="add" class="btn btn-primary"></th>
</thead>
<tbody class="detail">
<tr>
<td><select name="comname[]" type="text" class="form-control comname"><option id="0">-- Select Company --</option>
<?php $comp = $con->query("SELECT * FROM companys"); while ($vall = mysqli_fetch_array($comp)){?><option id="<?php echo $vall ['ID'];?>"> <?php echo $vall ['company']?></option><?php } ?></select></td>
<td><input name="claimed[]" type="text" class="form-control claimed" required placeholder="Invoice Amount"/></td>
<td><input name="rate[]" type="text" class="form-control rate" required placeholder="EX Rate"/></td>
<td><input name="netclaimed[]" type="text" class="form-control netclaimed" required placeholder="Invoice Amount"/></td>
<td><select name="reinsurer[]" type="text" class="form-control reinsurer">
<option id="0">-- Select Reinsurer --</option>
<option id="1">تكافلي</option>
<option id="2">تجاري</option>
</select></td>
<th><input type="button" value="-" id="remove" class="btn btn-primary"></th>
</tr>
</tbody>
<tfoot>
<th></th>
<th></th>
<th>Total</th>
<th class="total">0</th>
<th>LYD</th>
<th></th>
</tfoot>
</table>

</form>





<?php require('../includes/footer.php'); ?>

<script type="text/javascript">
$(function(){
$('#add').click(function(){
addnewrow();
});

$('body').delegate('#remove','click',function(){
$(this).parent().parent().remove();
});

$('.detail').delegate('.claimed, .rate', 'keyup',function(){
var tr = $(this).parent().parent();
var qty = tr.find('.claimed').val();
var rate = tr.find('.rate').val();
var amt = (qty * rate);
tr.find('.netclaimed').val(amt);
total();
});

});

function total(){
var t = 0;
$('.netclaimed').each(function(i,e)
{
var amt = $(this).val()-0;
t += amt;
});
$('.total').html(t);
}


function addnewrow()
{
var tr = '<tr>'+
'<td><select name="comname[]" type="text" class="form-control comname"><option id="0">-- Select Company --</option> <option id=""></option></select></td>'+
'<td><input name="claimed[]" type="text" class="form-control claimed" required placeholder="Invoice Amount"/></td>'+
'<td><input name="rate[]" type="text" class="form-control rate" required placeholder="EX Rate"/></td>'+
'<td><input name="netclaimed[]" type="text" class="form-control netclaimed" required placeholder="Invoice Amount"/></td>'+
'<td><select name="reinsurer[]" type="text" class="form-control reinsurer"><option id="0">-- Select Reinsurer --</option> <option id="1">تكافلي</option><option id="2">تجاري</option></select></td>'+
'<th><input type="button" value="-" id="remove" class="btn btn-primary"></th>'+
'</tr>';
$('.detail').append(tr);
}
</script>

最佳答案

如果选择不同,您需要 AJAX 内容,或者克隆而不是插入静态行:

function addnewrow() {
$('.detail').append($("tbody.detail tr:eq(0)").clone());
}

FIDDLE

关于javascript - 如何使用jquery add函数添加动态数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41461669/

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