简体   繁体   English

jQuery replaceWith在Firefox 42中不起作用

[英]jQuery replaceWith not working in Firefox 42

I've been using the following code as my jQuery jumpoff point for replacing content on some sites. 我一直使用以下代码作为jQuery的起点,用于替换某些网站上的内容。 On every site I've ued it, this bit of jQuery has worked without problem... until now. 在我使用过的每个网站上,jQuery的这一点都没有出现问题……直到现在。

For some reason, my replaceWith isn't working in Firefox on this one site and I can't seem to track down the reason. 由于某种原因,我的replaceWith在该站点的Firefox中无法正常工作,而且我似乎无法找到原因。

I've du around here looking for the answer and, while I've found other cases of replaceWith not working, none seem to point me in the right direction to figuring out/fixing my particualr issue. 我一直在这里寻找答案,尽管我发现其他方法replaceWith无法正常工作,但似乎没有人指出我正确的方向来解决/解决我的特殊问题。

So, below is my bit of script and, all I want to do is replace phone numbers in paragraphs and in the header top right area. 因此,下面是我的一些脚本,我要做的就是替换段落中和标题右上角的电话号码。 Again, it's working in Chrome, Edge, and Safari but, no go in Firefox. 同样,它可以在Chrome,Edge和Safari中使用,但在Firefox中则无法使用。

Oh, a link to the site I'm having the problem on: http://greenvilledisabilitylawyer.net/ 哦,我遇到问题的网站链接: http : //greenvilledisabilitylawyer.net/

jQuery(function($) {
    // NUM SWAP IN DIV
    $("li.menu-item-33").replaceWith(
        "<li id='menu-item-33' class='numbertop menu-item menu-item-type-custom menu-item-object-custom menu-item-33'><a href='tel:8643004994'> Free Consultation (864) 300-4994</a></div>"
    );
    // NUM SWAP IN PARAGRAPH
    $('p').not('.site-title').each(function() {
        var num1 = $(this).text().replace(/235-0886/g,
            "300-4994");
        $(this).text(num1);
    });
    // NUM SWAP IN PARAGRAPH
    $('p').not('.site-title').each(function() {
        var num2 = $(this).text().replace(/369-7200/g,
            "210-3290");
        $(this).text(num2);
    });
});

Not sure why it is not working in your side.Can you please check the console. 不知道为什么它不能在您身边工作。请检查控制台。 Here is a snippet that I tried with and it worked fine 这是我尝试过的一个片段,效果很好

JS JS

jQuery(function($) {
    // NUM SWAP IN DIV
  setTimeout(function(){
   $("li.menu-item-33").replaceWith(
        "<li id='menu-item-33' class='numbertop menu-item menu-item-type-custom menu-item-object-custom menu-item-33'><a href='tel:8643004994'> Free Consultation (864) 300-4994</a></li>");
  },5000)
});

NOTE: I used setTimeout just to trigger the change 注意:我使用setTimeout只是为了触发更改

WORKING DEMO 工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM