Javascript 如何从拆分数组函数中复制数据
我想向表中添加从文本拆分到数组的数据。当我点击add按钮时,数据显示在表中,并自动将价格和金额乘以Column总价。有人能帮我吗 这是htmlJavascript 如何从拆分数组函数中复制数据,javascript,html,arrays,split,Javascript,Html,Arrays,Split,我想向表中添加从文本拆分到数组的数据。当我点击add按钮时,数据显示在表中,并自动将价格和金额乘以Column总价。有人能帮我吗 这是html <div class="container"> <div class="form" style="margin-top: 50px;"> <div class="form"> <div class="form-group">
<div class="container">
<div class="form" style="margin-top: 50px;">
<div class="form">
<div class="form-group">
<label for="inputEmail3">Input</label>
<div class="">
<input type="text" class="form-control" id="transaction" placeholder="Input Transaction">
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-default" onclick="addTransaction()">Add</button>
</div>
</div>
</div>
</div>
<div class="row">
<table id="table_trans" class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Amount</th>
<th>Total Price</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<input type="button" value="Total Price" class="btn btn-success" id="sumTransaction()"/>
</td>
<td id="area_total"></td>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- /.container -->
输入
添加
名称
价格
数量
总价
这是分割函数
function addRow(tags){
var theTable = document.getElementById('table_trans').getElementsByTagName('tbody')[0];
var newRow = theTable.insertRow(-1);
var newCell, theText, i;
for(i=0;i<tags.length;i++){
newCell = newRow.insertCell(i);
theText = document.createTextNode(tags[i]);
newCell.appendChild(theText);
}
}
function addTransaction(){
var inputTags = document.getElementById('transaction').value;
addRow(inputTags.split(','));
}
函数addRow(标记){
var theTable=document.getElementById('table_trans').getElementsByTagName('tbody')[0];
var newRow=表格.insertRow(-1);
var newCell,theText,i;
对于(i=0;i就像这样,我将字符串传递到addRow
和split()
中,将价格
乘以金额
得到总计
,然后将总计
的值附加到标记
数组中:
函数addRow(标记){
tags=tags.split(',');
var总计=标签[1]*标签[2];
标签。推送(总计);
var theTable=document.getElementById('table_trans').getElementsByTagName('tbody')[0];
var newRow=表格.insertRow(-1);
var newCell,theText,i;
对于(i=0;i
输入
添加
名称
价格
数量
总价