我將此表轉換為模態形式:
<div class="form-group">
<!-- Record list -->
<table id="tabscarichi" class="table table-bordered table-striped" style='border-collapse: collapse;' >
<tr style='background: whitesmoke;'>
<th>Check</th>
<th>Id</th>
<th>Formulario</th>
<th>EER</th>
<th>Data FR</th>
<th>Q.tà</th>
</tr>
<?php
$query = "SELECT * FROM registro_c_s where stato_carico='1'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result) ){
$id = $row['id'];
$fr = $row['formulario'];
$data = $row['data_fr'];
$eer = $row['codice_eer'];
$qta = $row['quantità'];
$stato = $row['stato_carico'];
?>
<tr>
<!-- Checkbox -->
<td><input type='checkbox' class="box" name='update[]' value='<?= $id ?>' ></td>
<td><?= $id ?></td>
<td><?= $fr ?></td>
<td><?= $eer ?></td>
<td><?= $data ?></td>
<td class="qta_scarichi"><?= $qta ?></td>
</tr>
<?php
}
?>
</table>
</div>
我正在嘗試撰寫一個腳本來對 .qta_scarichi 類的值求和,并用 .qtas 類在另一個輸入數字中報告它。
我試過這個:
$('.box').change(function(){
var total = 0;
$('.box:checked').each(function(){
total =parseFloat($(this).parent().next('td').find('.qta_scarichi').text());
});
$('#qtà').val(total);
});
但是當我檢查一些行時..什么也沒發生..#qtà 是我想要填寫的輸入數字的 ID..
uj5u.com熱心網友回復:
發現問題!在 id="tabscarichi" 的表中,我有以下腳本:
$(function() {
$('#tabscarichi').hide();
$('#tipo').change(function(){
if($('#tipo').val() == 'scarico') {
$('#tabscarichi').show();
console.log('0'); }
else { $('#tabscarichi').hide();
} }); }); </script> ```
i choose to show the table with a select... if i disable the script.. the css selector works! But i don't understand why..
uj5u.com熱心網友回復:
$(this).parent().next('td')只是選擇<td><?= $id ?></td>,其中不包含.qta_scarichi.
使用$(this).closest('tr').find('.qta_scarichi').
我懷疑您可能打算“.siblings('td') . .next()` 只選擇緊隨其后的元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/315536.html
