2013-04-16 27 views
1
替換文本

是否有可能使用jQuery這樣當前標籤替換字符串:當前使用標籤內嵌的js

<td class="price"><script>$(this).text(accounting.formatMoney(parseFloat({{ product.price }}).toFixed(2), "€ ", 2, ".", ","));</script></td> 

其實這是行不通的。

在此先感謝!

回答

2

你可以將其設置在一個函數來完成,但直到頁面加載後......這樣的事情是你在找什麼?首先,改變你的HTML:

<td class="price">{{ product.price }}</td> 

然後這個腳本應該適合你:

$(function(){ 
    $('.price').each(function(){ 
     var price = $(this).text() 
     $(this).text(accounting.formatMoney(parseFloat(price).toFixed(2), "€ ", 2, ".", ",")) 
    }); 
});