0
我想我得到了與JS和HTML(引導)的問題, 我從bootsnip這些片段,並試圖修改它需要我的工作。 但在第三行,對於錯字或使用英語不好。計算選擇期權價值與jQuery
這裏bootsnip(我的修改):http://bootsnipp.com/snippets/o8r0G
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='name"+i+"' type='text' placeholder='Name' class='form-control input-md' /> </td><td><input name='mail"+i+"' type='text' placeholder='Mail' class='form-control input-md'></td><td><select class='form-control' name='slct"+i+"' placeholder='Select'><option value='1'>1</option><option value='2'>2</option></select></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
\t if(i>1){
\t \t $("#addr"+(i-1)).html('');
\t \t i--;
\t \t }
\t });
});
$('.buttonx').click(function() {
var total = 0;
$('#tab_logic tbody tr').each(function(index) {
var price = parseInt($(this).find('.optx sltx option value').text());
var quantity = parseInt($(this).find('.optx sltx option').val());
var value = $(this).find('.value');
var subTotal = price * quantity;
value.text(subTotal);
value.text(price);
total = total + subTotal;
testotal = price;
});
$('.totality').text('Total : '+testotal);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row clearfix">
\t \t <div class="col-md-12 column">
\t \t \t <table class="table table-bordered table-hover" id="tab_logic">
\t \t \t \t <thead>
\t \t \t \t \t <tr >
\t \t \t \t \t \t <th class="text-center">
\t \t \t \t \t \t \t #
\t \t \t \t \t \t </th>
\t \t \t \t \t \t <th class="text-center">
\t \t \t \t \t \t \t Value1
\t \t \t \t \t \t </th>
\t \t \t \t \t \t <th class="text-center">
\t \t \t \t \t \t \t Value2
\t \t \t \t \t \t </th>
\t \t \t \t \t \t <th class="text-center">
\t \t \t \t \t \t \t Select
\t \t \t \t \t \t </th>
\t \t \t \t \t </tr>
\t \t \t \t </thead>
\t \t \t \t <tbody>
\t \t \t \t \t <tr id='addr0'>
\t \t \t \t \t \t <td>
\t \t \t \t \t \t 1
\t \t \t \t \t \t </td>
\t \t \t \t \t \t <td>
\t \t \t \t \t \t <input type="text" name='va10' placeholder='Val1' class="form-control"/>
\t \t \t \t \t \t </td>
\t \t \t \t \t \t <td>
\t \t \t \t \t \t <input type="text" name='va20' placeholder='Val2' class="form-control"/>
\t \t \t \t \t \t </td>
\t \t \t \t \t \t <td class="optx">
\t \t \t \t \t \t <select class="form-control sltx" name="slct0" placeholder="Select"><option value="1">1</option><option value="2">2</option></select>
\t \t \t \t \t \t </td>
\t \t \t \t \t </tr>
<tr id='addr1'></tr>
\t \t \t \t </tbody>
<tfoot>
<tr>
<th></th>
<th></th>
<th><a id="buttonx" class="btn btn-default btn-danger pull-right">Calculate</a></th>
<th id="totality" style="vertical-align: middle;">Total : </th>
</tr>
</tfoot>
\t \t \t </table>
\t \t </div>
\t </div>
\t <a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a>
</div>
我試圖創建從總表,但我不能從表JS裝載值,也許我從其他答案中得到的腳本錯了。參考是在這裏:getting values from a html table via javascript/jquery and doing a calculation
我想問,我怎麼能從選擇選項的計算,或者從輸入文本框,沒有我按下按鈕(實時計算)。
由於之前。
總公式是什麼?它是'value1 + value2 + select value'? – kasperite
'value1' | 'value2' | 'value1 + value2 + select' –