为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 Javascript 设置默认选项?

如何使用 Javascript 设置默认选项?

qq_笑_17 2021-06-21 09:19:39
我正在尝试为游戏市场构建货币转换器,我目前拥有它,以便在输入栏中显示每种货币/付款方式的相应图标 - 它具有付款选项的默认选项,但跨度为空白直到用户点击一个国家。如何设置默认值以便图标 100% 出现?我设法使其与付款方式图标一起使用,但我缺少国家/地区图标的某些内容https://codepen.io/anon/pen/byXrWN    const data = [    {        currency: 'paypal',        we_buy: 0.50,        we_sell: 0.68,        img_path: 'img/paypal.svg',        icon: 'fab fa-paypal'    },    {        currency: 'debit',        we_buy: 0.67,        we_sell: 0.82,        img_path: 'img/debit-card.svg',        icon: 'far fa-credit-card'    },    {        currency: 'btc',        we_buy: 0.58,        we_sell: 0.77,        img_path: 'img/bitcoin.svg',        icon: 'fab fa-btc'    },    {        currency: 'ethereum',        we_buy: 0.59,        we_sell: 0.76,        img_path: 'img/ethereum.svg',        icon: 'fab fa-ethereum'    }];const country = [    {        country_id: 'USA',        country_currency: 'USD',        img_path: 'img/united-states.svg',        icon: 'fas fa-dollar-sign',        rate: 1.0    },    {        country_id: 'EUR',        country_currency: 'EUR',        img_path: 'img/european-union.svg',        icon: 'fas fa-euro-sign',        rate: 0.88    },    {        country_id: 'UK',        country_currency: 'GBP',        img_path: 'img/united-kingdom.svg',        icon: 'fas fa-pound-sign',        rate: 0.78    },      {        country_id: 'CAN',        country_currency: 'CAD',        img_path: 'img/canada.svg',        icon: 'fas fa-dollar-sign',        rate: 1.33    }];const countryContainer = document.getElementById("countries");let selectedCountry = null;var selectCountry = function (index) {    const cdata = country[index];    selectedCountry = country[index];    document.getElementById("country-selected").innerHTML = `Country selected: ${cdata.country_currency}`;    document.getElementById("country_icon").className = cdata.icon;};顶行是国家选择,底行是付款方式(在 html/js 中命名不当 - 货币 = 付款方式)付款方式的图标应在页面加载时出现,而不是在用户单击其原籍国之后
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信