を計算する:jQueryのは、私はこのようなテーブルに何かを持っている1つの関数に
sellingprice cost postage profit paypal ebayfees discount FVF
? 49 1.75 4.00 ? ? 0.2 ?
? 51 1.75 4.00 ? ? 0.2 ?
これは、上記の情報を解決するための異なる式です:
sellingpriceresult =コスト+送料+利益+ペイパル+ FVF;
paypalresult = sellpriceresult * 0.022 + 0.3;
FVFresult = ebayfees - (ebayfees * discount);条件は、それは結果だ。このような何かを表示する場合
ebayfeesresultを使用して次のようになります。
をもしsellingpriceresult> 50それから(sellingpriceresult - 50)*他に0.05 + 3.5
場合sellingpriceresult < = 50、その後sellingpriceresult * 0.07
クライアント側計算を使用して計算を実装したいと考えています。私の問題は、私はどのように1つの関数ですべての計算を組み合わせるのか分からないということです。私はjQueryについて少し考えており、皆さんにこの方法を教えてもらいたいと思います。どんな助けでももっと感謝します。ここで
は私のサンプルコードは次のとおりです。
<table border = "0">
<tr>
<td><center>Selling Price</center></td>
<td><center>Cost</center></td>
<td><center>Postage</center></td>
<td><center>Profit</center></td>
<td><center>Paypal</center></td>
<td><center>eBay Fees</center></td>
<td><center>Discount</center></td>
<td><center>FVF</center></td>
</tr>
<tr>
<td>
<input type='text' id='sellingprice' name='sellingprice' size='10' readonly='true'/>
</td>
<td>
<input type='text' id='cost' name='cost' size='10' value='$myrow[1]' readonly='true'/>
</td>
<td>
<input type='text' id='postage' name='postage' size='10' value='1.75' readonly='true'/>
</td>
<td>
<input type='text' id='profit' name='profit' size='10' value='4.00' readonly='true'/>
</td>
<td>
<input type='text' id='paypal' name='paypal' size='10' readonly='true'/>
</td>
<td>
<input type='text' id='ebayfees' name='ebayfees' size='10' readonly='true'/>
</td>
<td>
<input type='text' id='discount' name='discount' size='10' value='0.2' readonly='true'/>
</td>
<td>
<input type='text' id='fvf' name='fvf' size='10' readonly='true'/>
</td>
</tr>
</table>
<script>
$(document).ready(function(){
$('tr').each(function(){
var sellingprice = 0;
$(this).find("input[name=cost],input[name=postage],input[name=profit],input[name=paypal],input[name=fvf]").each(function(){
sellingprice += (+$(this).val());
});
$(this).find("input[name=sellingprice]").val(sellingprice).css("background-color", "yellow");
});
});
$(document).ready(function(){
$('tr').each(function(){
var paypal = 0;
$(this).find("input[name=sellingprice]").each(function(){
paypal = (+$(this).val()) * 0.022 + 0.3;
paypal = paypal.toFixed(2);
});
$(this).find("input[name=paypal]").val(paypal).css("background-color", "yellow");
});
});
$(document).ready(function(){
$('tr').each(function(){
var sellingprice = 0;
$(this).find("input[name=cost],input[name=postage],input[name=profit],input[name=paypal],input[name=fvf]").each(function(){
sellingprice = (+$(this).val());
sellingprice = sellingprice.toFixed(2);
});
$(this).find("input[name=sellingprice]").val(sellingprice).css("background-color", "yellow");
});
});
$(document).ready(function(){
$('tr').each(function(){
var fvf = 0;
$(this).find("input[name=ebayfees],input[name=discount]").each(function(){
fvf = (+$(this).val());
});
$(this).find("input[name=fvf]").val(fvf).css("background-color", "yellow");
});
});
$(document).ready(function(){
$('tr').each(function(){
var sellingprice = 0;
$(this).find("input[name=cost],input[name=postage],input[name=profit],input[name=paypal],input[name=fvf]").each(function(){
sellingprice += (+$(this).val());
});
$(this).find("input[name=sellingprice]").val(sellingprice).css("background-color", "yellow");
});
});
$(document).ready(function(){
$('tr').each(function() {
var sellingpriceResult = parseFloat($(this).find("input[name=sellingprice]").val());
var result = 0;
if (sellingpriceResult > 50) {
result = (sellingpriceResult - 50) * 0.05 + 3.5;
result = result.toFixed(2);
}
else {
result = sellingpriceResult * 0.07;
result = result.toFixed(2);
}
$(this).find("input[name=ebayfees]").val(result).css("background-color", "yellow");
});
});
</script>
コストの値は '$ myrow [1]'です...私はそれがtypohだと思います。 –
コストコラムを記入するためにデータベースにフェッチされているので – jovazel