gpt4 book ai didi

javascript - Javascript 字符串中的美元符号

转载 作者:行者123 更新时间:2023-11-30 06:57:22 25 4
gpt4 key购买 nike

我想解析一个元素并按货币设置区域。

HTML:

<span id="price">¥82,84</span><br/>

Javascript:

        price = document.getElementById("price").innerHTML;
price = price.slice(0,1);

if(price == "€")
{
area = "europe";
}
if(price == "£")
{
area = "europe";
}
if(price == "\$")
{
area == "northamerica";
}
if(price == "\¥")
{
area == "asia";
}

欧元和英镑有效,但日元和美元无效。有人有想法吗?

最佳答案

您在应该使用赋值运算符 = 的语句中使用了相等比较 ==

关于javascript - Javascript 字符串中的美元符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9144464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com