我想計算並顯示一個簡單的jquery函數,但沒有顯示出來。jquery簡單的計算功能
這是jQuery代碼:
function compute() {
var a = $('#a').val();
var b = $('#pln').val();
var c = $('#c').val();
var d = a*b;
var total = d+c;
$('#total').val(total.toFixed(2));
}
$('#a, #b, #c, #d').change(compute);
這是形式的代碼,我要實現它,並顯示計算值。
<div>
<label style="margin-top: 25px;">Timer duration</label>
<input type="radio" id="mc a" name="optionsRadios" value="<?php echo $at_fetch['at_mc']; ?>" style="margin-left: -170px; margin-top: 3px;">
<font style='margin-left: -170px; font-family: "Lucida Sans Unicode",Arial;'><?php echo $at_fetch['at_mc']; ?> secs (Micro Ads)</font><br />
<input type="radio" id="mn a" name="optionsRadios" value="<?php echo $at_fetch['at_mn']; ?>" style="margin-left: -170px; margin-top: 3px;">
<font style='margin-left: -170px; font-family: "Lucida Sans Unicode",Arial;'><?php echo $at_fetch['at_mn']; ?> secs (Mini Ads)</font><br />
<input type="radio" id="sd a" name="optionsRadios" value="<?php echo $at_fetch['at_sd']; ?>" style="margin-left: 62px; margin-top: 3px;">
<font style='margin-left: -170px; font-family: "Lucida Sans Unicode",Arial;'><?php echo $at_fetch['at_sd']; ?> secs (Standard Ads)</font><br />
<input type="radio" id="fd a" name="optionsRadios" value="<?php echo $at_fetch['at_fd']; ?>" style="margin-left: 62px; margin-top: 3px;">
<font style='margin-left: -170px; font-family: "Lucida Sans Unicode",Arial;'><?php echo $at_fetch['at_fd']; ?> secs (Fixed Ads)</font><br />
</div>
<div style="margin-top: -60px;">
<label>Choose plan</label>
<select name="" id="pln" class="select-box" style="margin-top: -40px;" />
<option value="0">Choose clicks</option>
<?php while($ac_fetch = mysql_fetch_array($qur_ac)){ ?>
<option value="<?php echo $ac_fetch['adclk_clicks']; ?>"><?php echo $ac_fetch['adclk_clicks']; ?> clicks</option>
<?php } ?>
</select>
</div>
<div>
<label>Fees</label>
$<?php echo $paf_fetch['paf_fees']; ?>
<input type="hidden" id="c" value="<?php echo $paf_fetch['paf_fees']; ?>" />
</div>
<div>
<label>Total
<input type="text" id="total" value="" disabled>
</div></label>
<br /><br />
我想這個jQuery計算在<input type="text" id="total" value="" disabled>
的價值觀和顯示。但它沒有顯示。請幫我解決這個問題。
'div'沒有財產'value'。你應該嘗試'.html()'或'.text()' – Rajesh