我在html中创建一个表格,我必须在折扣后计算价格。
我目前有2行7个标题单元格,在每个标题单元格下面我有一个单元格。我正在努力为我的细胞增加价值。我尝试了这个var cells = document.getElementById('table').getElementsByTagName('td');
cells[1] = "3";
将值3添加到我的数量,但该值没有出现在我的桌子上。我想这样做,所以我可以稍后将转换功能应用到我的所有TDS。
我做错了什么?
/* Format amount */
function ConvertAmount(Amount) {
var cells = document.getElementById('table').getElementsByTagName('td');
cells[1] = "3";
var Zahl = Amount;
Zahl = Math.round(Zahl * Math.pow(10, 2)) / Math.pow(10, 2);
Zahl = Zahl.toFixed(2);
Zahl = Zahl.toString();
var Negativ = false;
if (Zahl.indexOf("-") == 0) {
Negativ = true;
Zahl = Zahl.replace("-", "");
}
var str = Zahl.toString();
str = str.replace(".", ",");
var intVorkommastellen = str.length - (str.length - str.indexOf(","));
var intKTrenner = Math.floor((intVorkommastellen - 1) / 3);
var intZiffern = (intVorkommastellen % 3 == 0) ? 3 : (intVorkommastellen % 3);
strNew = str.substring(0, intZiffern);
strHelp = str.substr(intZiffern, (str.length - intZiffern));
for (var i = 0; i < intKTrenner; i++) {
strNew += "." + strHelp.substring(0, 3);
strHelp = strHelp.substr(intZiffern, (strHelp.length - intZiffern));
}
var szNachkommastellen = str.substring(intVorkommastellen, str.length);
if (szNachkommastellen.length < 3) {
strNew += str.substring(intVorkommastellen, str.length) + '0';
} else {
strNew += str.substring(intVorkommastellen, str.length);
}
var Zahl = strNew;
if (Negativ) {
Zahl = "- " + Zahl;
}
return Zahl;
}
&#13;
.briefkopf {
margin-top: 5px;
}
.ueberschrift {
font-size: 20pt;
font-weight: bolder;
}
.unterueberschrift {
font-size: 14pt;
}
.dagufarbe {
color: #EC7404;
}
body {
margin: 0;
padding: 0;
font: 12pt"Arial";
}
.page {
width: 21cm;
min-height: 29.7cm;
padding: 1cm;
margin-left: 50px;
}
.subpage {
padding: 1cm;
border: 5px red solid;
height: 256mm;
outline: 2cm #FFEAEA solid;
page-break-before: always;
page-break-after: always;
}
@page {
size: A4;
margin: 0;
}
@media print {
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
}
&#13;
<div class="page">
<div class="briefkopf">
<br>
<br>
<br>
<div>
<script type="text/javascript">
</script>
</div>
<div>street</div>
<div>number</div>
<div>country</div>
</div>
<br>
<br>
<div class="ueberschrift">Offer from
<script type="text/javascript">
document.write(Invoicedate)
</script>
</div>
<br>
<style type="text/css">
.tg {
border-collapse: collapse;
border-spacing: 0;
}
.tg td {
font-family: Arial, sans-serif;
font-size: 12pt;
padding: 10px 5px;
border-width: 1px;
border-style: none none solid;
}
.tg th {
font-family: Arial, sans-serif;
font-size: 12pt;
font-weight: normal;
padding: 10px 5px;
border-width: 3px;
border-style: none none solid;
}
</style>
<table id="table" class="tg" style="width:900px;">
<tr>
<th align="center" class="tg">Pos</th>
<th id="Quantity" align="center" class="tg">Quantity</th>
<th align="center" class="tg">Type</th>
<th align="left" class="tg">Description</th>
<th align="center" class="tg" style="width:100px;">Unitprice</th>
<th align="center" class="tg" style="width:75px;">Discount</th>
<th align="center" class="tg">Totalprice</th>
</tr>
<tr style="page-break-inside:avoid;">
<td align="right" class="tg" valign="top">
<center>
<script type="text/javascript">
document.write(ConvertAmount('{{POSITION}}'))
</script>
</center>
</td>
<td align="right" class="tg" valign="top">
<center>
<script type="text/javascript">
document.write(ConvertAmount('{{QUANTITY}}'))
</script>
</center>
</td>
<td align="right" class="tg" valign="top">
<center>
<script type="text/javascript">
document.write(ConvertAmount('{{ART}}'))
</script>
</center>
</td>
<td align="left" class="tg">
<div class="dagufarbe">
<center>
<script type="text/javascript">
document.write(ConvertAmount('{{DESCRIPTION}}'))
</script>
</center>
</div>
<br>
<div style="margin-top:-15px;">
<script type="text/javascript">
document.write(ConvertAmount('{{COMMENTARY}}'))
</script>
</div>
</td>
<td align="right" class="tg" valign="top">
<script type="text/javascript">
document.write(ConvertAmount('{{UNITPRICE}}'))
</script>€</td>
<td align="right" class="tg" valign="top">
<script type="text/javascript">
document.write(ConvertAmount('{{DISCOUNT}}'))
</script>%</td>
<td align="right" class="tg" valign="top">
<script type="text/javascript">
document.write(ConvertAmount('{{POSITIONSPRICE}}'))
</script>€</td>
</tr>
</table>
<style type="text/css">
.ta {
font-family: Arial, sans-serif;
font-size: 12pt;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.tb {
font-family: Arial, sans-serif;
font-size: 12pt;
font-weight: normal;
padding: 10px 5px;
border-width: 3px;
border-style: none none solid;
}
.te {
font-family: Arial, sans-serif;
font-size: 12pt;
font-weight: normal;
padding: 10px 5px;
border-style: none none solid;
}
</style>
<table style="width:575px; margin-left:330px;">
<tr>
<td class="ta">Total nett
<div style="margin-left:500px; margin-top:-20px;">
<script type="text/javascript">
document.write(ConvertAmount('{{AMOUNTNETT}}'))
</script>€</div>
<br>
</td>
</tr>
<tr>
<td class="te">
<div style="margin-top:-25px;">plus VAT 19,00 %</div>
<div style="margin-left:500px; margin-top:-20px;">
<script type="text/javascript">
document.write(ConvertAmount('{{AMOUNTTAX}}'))
</script>€</div>
<br>
</td>
</tr>
<tr>
<td class="tb"><b>Total amount <div style="margin-left:500px; margin-top:-20px;"><script type="text/javascript">document.write(ConvertAmount('{{AMOUNTGROSS}}'))</script> €</div></b>
</td>
</tr>
</table>
<br>
</div>
<br>
</p>
&#13;