我有數量單元格爲可修改時,它需要與其他父母的td值相乘時可編輯表格。這裏是我的代碼
(即)如果我將數量更改爲2,則父行需要乘以2乘以表td值
$(document).ready(function(){
$('.quantity').on('change, keyup',function(){
\t \t var tbvalue=$(this).parents('td').val();
console.log(tbvalue);
var val=$(this).val();
var result=tbvalue*val;
console.log(result);
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<h2>Table calculation</h2>
<p>Calculaton</p>
<table class="table table-hover">
<thead>
<tr>
<th>value1</th>
<th>value2</th>
<th>value3</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>10</td>
<td>5</td>
<td>4</td>
<td class="quantity" type="number" contenteditable>1</td>
</tr>
<tr>
<td>8</td>
<td type>2</td>
<td>3</td>
<td class="quantity" type="number" contenteditable>1</td>
</tr>
<tr>
<td>20</td>
<td>3</td>
<td>5</td>
<td class="quantity" type="number" contenteditable>1</td>
</tr>
</tbody>
</table>
</div>
'變種tbvalue = $(本)的.text();' –