问题描述
我有一个包表。我想根据用户的位置自动更改每个金额的货币。例如,如果用户来自英国,它将变为英镑,如果来自澳大利亚,则为澳元。我在谷歌搜索了一个教程,但所有我能看到的是一个转换表,不。如何使用HTML和JavaScript来做到这一点? < 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可以处理许多不同的格式,包括货币。
这些格式基于不同的语言设置,可在此处找到。
使用这个你甚至可以处理货币符号,但也显示数据的格式。
要获取访问者的语言,您可以使用类似这样的内容
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 € ^^
这篇关于根据国家更改货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!