我想在javascript的html中显示一些整数值,但不幸的是.html和.text都不起作用
这是我的代码
<script type="text/javascript">
$(".total").text("<?php echo $row_price['product_price'] + $economy; ?>");
$('input:radio[name="shipping_type"]').change(function(){
if($(this).val() == "economy"){
$(".total").text("<?php echo $row_price['product_price'] + $economy; ?>");
}else{
$(".total").text("<?php echo $row_price['product_price'] + $fast; ?>")
}
});
</script>
通过检查源代码值是否成功进入.text()函数。控制台以及html上均未显示任何错误
<tr>
<td class='radio-container'>
<input checked="checked" id="shipping_type_economy" name="shipping_type" type="radio" value="economy" />
</td>
<td><label for="shipping_type_domestic">Economy</label></td>
<td class='right'>
<span class="economy">10.20$</span>
</td>
</tr>
<tr>
<td class='radio-container'>
<input id="shipping_type_fast" name="shipping_type" type="radio" value="fast" />
</td>
<td><label for="shipping_type__fast">Fast</label></td>
<td class='right'>
<span class="fast">20.00$</span>
</td>
</tr>
<tr><td>TOTAL</td>
<td class="right" id="total"><span class="total"><span/></td>
</tr>
您的代码是正确的,只需将您的Jquery代码包装在$(document).ready(function(){..})块中,如下所示:-
$(document).ready(function(){
//Jquery Code
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句