2014-12-06 30 views
1

我想顯示在HTML中,某些整數值JavaScript,但不幸的是這兩個.html和的.text不工作.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> 
+0

是在服務器端運行PHP的一部分? – Leo 2014-12-06 08:04:04

回答

0

你的代碼是正確的,只是包裝jQuery代碼內$(document).ready(function(){..})塊,如下圖所示: -

$(document).ready(function(){ 
    //Jquery Code 
}); 
+0

十分感謝... – user1hjgjhgjhggjhg 2014-12-06 08:05:34

+0

@ user1hjgjhgjhggjhg ......歡迎您.. !!! – 2014-12-06 08:06:55

+0

以及如果我錯過了這一點,應該給我看在控制檯上的錯誤,但它不 – user1hjgjhgjhggjhg 2014-12-06 09:01:59

0

您正在使用jQuery的語法,這就需要你有包括jQuery庫。 jQuery是一個JavaScript之上的庫。 http://jquery.com/,除此之外,需要被包裹在一個文檔準備語句的代碼。

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

....your code 

}); 
</script>