我正在嘗試為游戲市場構(gòu)建貨幣轉(zhuǎn)換器,我目前擁有它,以便在輸入欄中顯示每種貨幣/付款方式的相應圖標 - 它具有付款選項的默認選項,但跨度為空白直到用戶點擊一個國家。如何設置默認值以便圖標 100% 出現(xiàn)?我設法使其與付款方式圖標一起使用,但我缺少國家/地區(qū)圖標的某些內(nèi)容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 中命名不當 - 貨幣 = 付款方式)付款方式的圖標應在頁面加載時出現(xiàn),而不是在用戶單擊其原籍國之后
如何使用 Javascript 設置默認選項?
qq_笑_17
2021-06-21 09:19:39