根据国家更改货币 [英] Change currency depending on country
问题描述
< style>
td {
text-align:center;
}
< / style>
< table>
< tr>
< td>< / td>
< td>
$ 100
< / td>
< td>
$ 200
< / td>
< td>
$ 300
< / td>
< / tr>
< tr>
< td>
套餐A
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< / tr>
< tr>
< td>
套餐B
< / td>
< td>
< input type =checkboxdisabled />
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< / tr>
< tr>
< td>
套餐C
< / td>
< td>
< input type =checkboxdisabled />
< / td>
< td>
< input type =checkboxdisabled />
< / td>
< td>
< input type =checkboxchecked disabled />
< / td>
< / tr>
< / table>
您可能想看看Globalize.js可以处理许多不同的格式,包括货币。
https:// github.com/jquery/globalize
https://github.com/jquery/globalize/blob/master/doc/api/currency/currency-formatter.md
这些格式基于不同的语言设置,可在此处找到 https://github.com/jquery/globalize/blob/master/doc/cldr.md 。
使用这个你甚至可以处理货币符号,但也显示数据的格式。
要获取访问者的语言,您可以使用类似这样的内容
Var language = window.nav igator.userLanguage || window.navigator.language;
alert(language); //作品IE / SAFARI / CHROME / FF
但请注意,一美元!一欧元€^^
I have a package table. I want to change automatically the currency of each amount depending on the location of the user. For example, if the user is from UK, it will change to pounds, if from Australia it will be AUD. I have looked for a tutorial in google but all I can see is a conversion table, like this one not. How will I do this using HTML and javascript?
<style>
td{
text-align: center;
}
</style>
<table>
<tr>
<td></td>
<td>
$100
</td>
<td>
$200
</td>
<td>
$300
</td>
</tr>
<tr>
<td>
Package A
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
</tr>
<tr>
<td>
Package B
</td>
<td>
<input type="checkbox" disabled/>
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
</tr>
<tr>
<td>
Package C
</td>
<td>
<input type="checkbox" disabled/>
</td>
<td>
<input type="checkbox" disabled/>
</td>
<td>
<input type="checkbox" checked disabled/>
</td>
</tr>
</table>
You may want to take look at Globalize.js which can handle many different formats including currency.
https://github.com/jquery/globalize
https://github.com/jquery/globalize/blob/master/doc/api/currency/currency-formatter.md
Those formats are based on different language settings which are available here https://github.com/jquery/globalize/blob/master/doc/cldr.md.
Using this you can even handle currency symbols but also display format of your data.
To get the language of your visitor you can use something like this
Var language = window.navigator.userLanguage || window.navigator.language;
alert(language); //works IE/SAFARI/CHROME/FF
But keep in mind that one USD $ !== one Euro € ^^
这篇关于根据国家更改货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!