.html和 .text 不起作用

.html and .text not working

本文关键字:不起作用 text html      更新时间:2023-09-26

我想在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
});

您正在使用 jQuery 语法,该语法要求您包含 jQuery 库。 jQuery是javascript之上的一个库。 http://jquery.com/,除此之外,代码需要包装在 doc ready 语句中。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
....your code
});
</script>