Javascript/jQuery 在 Chrome 中完美运行,但在 Firefox 中运行不佳

标签 javascript jquery html css

我最近一直在使用一些代码,允许人们在以英镑货币使用我们的网站时使用 Paypal Express Checkout 付款,但我不希望他们在使用欧元、美元或任何其他货币时使用该选项货币。

在我使用的自定义 CSS 中

.paypalbutton {display: none !important;}

然后在我使用的 Javascript/Jquery 中

window.setInterval(function(){
if (jQuery(".currency-selector:contains('GBP')").length) {
    jQuery(".paypalbutton").attr('style', 'display: inline-block !important');
 } 1000});

我这样做的原因是因为 Paypal 按钮是用 PHP 动态加载的。由于某种原因,.on 和 .live 似乎不起作用。

现在这在 Google Chrome 中完美运行,这是我一直在测试的。但由于某种原因,这在 Firefox 中不起作用(尚未测试其他浏览器)。所以我的问题是,为什么它不能在 Firefox 中运行?

感谢您的帮助。

更多信息:

当在控制台中输入代码时,在 Firefox 中似乎没有任何问题,只是在“GBP”上应该显示的 paypal 按钮在 Firefox 中没有显示,但在 Chrome 中显示。

Chrome 有:

.paypalbutton {display: inline-block !important}
<strike>.paypalbutton {display: none !important}</strike>

Firefox 有:

.paypalbutton {display: none !important}
<strike>.paypalbutton {display: inline-block !important}</strike>

最佳答案

您在定义 setInterval 函数时出错

尝试如下:

window.setInterval(function(){
  if(jQuery(".currency-selector:contains('GBP')").length){
    jQuery(".paypalbutton").attr('style', 'display: inline-block !important');
    /*jQuery(".paypalbutton").css({
       'display' : 'inline-block !important'
      });*/
 }
},1000);

Note : Console your output from both browsers. Check if there is any Script Error. Check if Javascript disabled/not supported by browser.

这是setInterval函数语法

window.setInterval(myCallbackFunction, DurationInMilliseconds);

示例:

var intervalID = window.setInterval(myCallback, 500);
function myCallback() {
  // Your code here
}

More details about setInterval() function. And jQuery Browser Support

关于Javascript/jQuery 在 Chrome 中完美运行,但在 Firefox 中运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43068148/

相关文章:

javascript - 如何将下一个上一个按钮添加到 js jQuery slider ?

javascript - 当我清除选项时,选择 onChange 不再起作用

php - 修改此 JS Focus 函数以使用动态设置 Select 选项的 PHP 函数

jquery - 表行上的单击事件,类 ="someClass"的 td 除外

javascript - 无论元素是否已使用 jQuery 添加到 DOM,都应用样式

javascript - JQUERY/JAVASCRIPT - 需要使用 JavaScript 代码从 jquery 对话框上的 <Select> 获取值

html - 为什么我的引导下拉菜单占据了网站的整个宽度,即使它很小

javascript - 如果 LocalStorage 中的复选框值等于 "true"getItem 已选中

javascript - 与子方法的方法链接

javascript - Brunch编译的JS跑不起来