2010-03-05 54 views
4

我已經用價格值生成了輸入。如何用jQuery替換輸入值中的符號?

實施例:

<input type="text" value="59,00"/> 

現在我應該用jQuery取代,(逗號)與.(點)。

我試過,但它不工作:

$('#inputid[value~=,]').each(function(i){  
    $(this).text($(this).text().replace(',','.')) 
}); 

能不能幫我

+0

,你應該使用正則表達式,http://www.java2s.com/Code/JavaScript/開發/ RegularExpressionsReplacingStringsviaRegularExpressions.htm – ant 2010-03-05 16:49:18

回答

4
$('input:text').each(function() { 
    var value = $(this).val(); 
    $(this).val(value.replace(/\,/i, '.')); 
});