我想从 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(){..}) 中即可 block 如下所示:-
$(document).ready(function(){
//Jquery Code
});
关于javascript - .html 和 .text 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27329628/