<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script src="js/jquery-3.4.1.min.js"></script>
<table width="80%" border="1" align="center" id="test">
<tr>
<td width="69">列值</td>
<td width="69">整数一</td>
<td width="69">整数二</td>
<td width="54">总和</td>
</tr>
<tr>
<td>1</td>
<td><input type="text" name="textfield" onchange="count(this)"></td>
<td><input type="text" name="textfield3" onchange="count(this)"></td>
<td><input type="text" name="textfield5" disabled></td>
</tr>
<tr>
<td>2</td>
<td><input type="text" name="textfield2" onchange="count(this)"></td>
<td><input type="text" name="textfield4" onchange="count(this)"></td>
<td><input type="text" name="textfield6"disabled></td>
</tr>
<tr>
<td>合计</td>
<td><input type="text" name="textfield2" disabled></td>
<td><input type="text" name="textfield4" disabled></td>
<td><input type="text" name="textfield6" disabled></td>
</tr>
</table>
<script type="text/javascript">
function count(x) {
let value1=$(x).parents("tr").find("td:eq(1) input[type=text]").val();
let value2=$(x).parents("tr").find("td:eq(2) input[type=text]").val();
let sum = value1 * value2
$(x).parents("tr").find("td:eq(3) input[type=text]").val(sum);
}
</script>
</body>
</html>
JS实现类似excel的表格数据输入,并自动计算的页面
猜你喜欢
转载自blog.csdn.net/qq_44739706/article/details/114142968
今日推荐
周排行