gpt4 book ai didi

javascript - 如何自动选择特定选项

转载 作者:行者123 更新时间:2023-11-28 09:19:45 25 4
gpt4 key购买 nike

我的网站使用货币转换器 (shopify),即使我的商店接受英镑,我也想自动选择货币美元,以便在进入网站时,价格会转换为美元

以下是我的货币转换器代码

<label for="currencies">Currency converter </label>
<select id="currencies" name="currencies">
{% capture codes %},USD,EUR,GBP,CAD,ARS,AUD,BBD,BDT,BSD,BHD,BRL,BOB,BND,BGN,MMK,KYD,CLP,CNY,COP,CRC,HRK,CZK,DKK ,DOP,XCD,EGP,XPF,FJD,GHS,GTQ,GYD,GEL,HKD,HUF,ISK,INR,IDR,NIS,JMD,JPY,JOD,KZT,KES,KWD,LVL,LTL,M XN,MYR,MUR,MDL,MAD,MNT,MZN,ANG,NZD,NGN,NOK,OMR,PKR,PYG,PEN,PHP,PLN,QAR,RON,RUB,SAR,RSD,SCR,SGD ,SYP,ZAR,KRW,LKR,SEK,CHF,TWD,THB,TZS,TTD,TRY,UAH,AED,UYU,VEB,VND,ZMK,{% endcapture %}
{% assign supported_codes = settings.supported_currencies | split: ' ' %}
<option value="{{ shop.currency }}" selected="selected">{{ shop.currency }}</option>
{% for code in supported_codes %}
{% if code != shop.currency and codes contains code %}
<option value="{{ code }}">{{ code }}</option>
{% endif %}
{% endfor %}
</select>

如何自动选择显示美元?

最佳答案

您可以使用 JavaScript 轻松完成此操作,如下所示:

http://jsfiddle.net/83wHb/

基本上,您想要运行一个加载脚本,将货币值(value)设置为美元。

理想情况下,您希望在加载时运行脚本,或者在渲染选择元素后立即运行脚本。

<script>
document.getElementById('currencies').value = "USD";
//console.log('current value selected: ' + document.getElementById('currencies').value);
</script>

或者(可能更好),您可以像这样在服务器端执行此操作:

<label for="currencies">Currency converter </label>
<select id="currencies" name="currencies">
{% capture codes %},USD,EUR,GBP,CAD,ARS,AUD,BBD,BDT,BSD,BHD,BRL,BOB,BND,BGN,MMK,KYD,CLP,CNY,COP,CRC,HRK,CZK,DKK ,DOP,XCD,EGP,XPF,FJD,GHS,GTQ,GYD,GEL,HKD,HUF,ISK,INR,IDR,NIS,JMD,JPY,JOD,KZT,KES,KWD,LVL,LTL,M XN,MYR,MUR,MDL,MAD,MNT,MZN,ANG,NZD,NGN,NOK,OMR,PKR,PYG,PEN,PHP,PLN,QAR,RON,RUB,SAR,RSD,SCR,SGD ,SYP,ZAR,KRW,LKR,SEK,CHF,TWD,THB,TZS,TTD,TRY,UAH,AED,UYU,VEB,VND,ZMK,{% endcapture %}
{% assign supported_codes = settings.supported_currencies | split: ' ' %}
<option value="{{ shop.currency }}" >{{ shop.currency }}</option>
{% for code in supported_codes %}
{% if code != shop.currency and codes contains code %}
{% if code == 'USD' %}
<option value="{{ code }}" selected="selected"> {{ code }}</option>
{% else %}
<option value="{{ code }}">{{ code }}</option>
{% endif %}
{% endif %}
{% endfor %}
</select>

关于javascript - 如何自动选择特定选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15180601/

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