gpt4 book ai didi

javascript - 使用 jQuery javascript 根据域显示内容

转载 作者:行者123 更新时间:2023-12-03 10:00:51 24 4
gpt4 key购买 nike

大家好,我有一个带有 2 个域的网站,一个是 .com,另一个是 .us 我正在尝试让它显示一个标志选择国家/地区域名,因此如果单击链接以定向到 .us,我想显示美国国旗:

到目前为止我已经做到了,但有时有效,但有时无效,我不知道为什么!

HTML:

<li>Currency <img class="usd-flag" style="display:none" src="/images/usd-flag.svg" width="20" height="14" alt="USD CURRENCY $;"/><img class="gbp-flag" style="display:none" src="/images/gbp-flag.svg" width="20" height="14" alt="GBP CURRENCY &pound;"/>
<ul>
<li><a href="http://www.example.com">BRITISH POUNDS ( &pound; ) </a></li>
<li><a href="http://www.example.us">US DOLLARS ( $ )</a></li>
</ul>
</li>

JS:

if(location.href.indexOf('.us') >= 0) {
$('.usd-flag').show();
$('.gbp-flag').hide();
}
if(location.href.indexOf('.com') >= 0) {
$('.gbp-flag').show();
$('.usd-flag').hide();
}//changes flag image depending on domain

有人可以告诉我这里出了什么问题吗?

最佳答案

您可以使用液体 if else 语句并使用 contains 来完成此操作。

{% if {{globals.site.host}} contains '.us' %}

<div>this is a .us domain</div>

{% else %}

<div>This is a .com domain</div>

{% endif %}

或者您也可以使用 2 个 if 语句。而不是其他,具体取决于您的需要。

此处使用 AU 域的临时示例。

http://liquiddev.rtweb.com.au/domain

希望对你有帮助!

关于javascript - 使用 jQuery javascript 根据域显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30606854/

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