You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress 6.4.2中Select控制Div显示/隐藏的JS代码失效问题

问题:WordPress 6.4.2中货币选择联动显示/隐藏提示框失效

我有一段JS代码在JSFiddle里能正常运行,功能是根据下拉选框的货币选项值来显示或隐藏提示Div,但放到我的WordPress 6.4.2网站(PINKEQUINE)上就完全没效果。需求是:当选中的货币不是GBP时,显示购物车结账按钮下方的提示消息;选GBP时隐藏。我试了两种JS写法都没用,搞不清问题出在哪。

相关代码

下拉选框HTML代码

<div class="widget "> <form>
<select name="currency" id="currency" aria-label="" onchange="if (!window.__cfRLUnblockHandlers) return false; this.form.submit()">
<option value="GBP">🇬🇧 £ GBP</option>
<option value="AUD" selected="">🇦🇺 $ AUD</option>
<option value="CAD">🇨🇦 $ CAD</option>
<option value="EUR">🇪🇺 € EUR</option>
<option value="JPY">🇯🇵 ¥ JPY</option>
<option value="NZD">🇳🇿 $ NZD</option>
<option value="ZAR">🇿🇦 R ZAR</option>
<option value="USD">🇺🇸 $ USD</option> 
</select>
</form>
</div>

 <div class="currency-msg" >
 Please change currency to GBP to see Clearpay and PayPal installment options
 </div>

第一种JS代码

$(document).ready(function(){
var Currency = jQuery('#currency');
var select = this.value;
$('.currency-msg').hide();
Currency.change(function () {
    if ($(this).val() != 'GBP') {
        $('.currency-msg').show();
    }
    else $('.currency-msg').hide(); // hide div if value is  "GBP"
});

});

第二种JS代码

jQuery(document).ready(function(){
   
        var Currency = jQuery('#currency');
        var select = this.value;
        
        Currency.change(function () {
            if ($(this).val() != 'GBP') {
                $('.currency-msg').css('display','block');
            }
            else $('.currency-msg').css('display','none'); // hide div if value is  "GBP"
        });
        
     
    });

内容的提问来源于stack exchange,提问作者pinkequine

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 04:49:52