Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery搜索和替换不工作(Wordpress)_Javascript_Jquery_Wordpress_Search_Replace - Fatal编程技术网

Javascript jQuery搜索和替换不工作(Wordpress)

Javascript jQuery搜索和替换不工作(Wordpress),javascript,jquery,wordpress,search,replace,Javascript,Jquery,Wordpress,Search,Replace,我一定试过半打脚本(大多数都在这里找到,例如at)来替换Wordpress构建站点()上的文本 没用。我不够聪明,不知道为什么(但也不够愚蠢,不知道如何运行脚本)。脚本以通常的方式进入header.php,但没有结果 例如,我的主页上的所有“Shop”实例(在菜单中,h2元素,在Wordpress内容中)保持不变,尽管有这个脚本 $("span, p, div").each(function() { var text = $(this).text(); text = text.r

我一定试过半打脚本(大多数都在这里找到,例如at)来替换Wordpress构建站点()上的文本

没用。我不够聪明,不知道为什么(但也不够愚蠢,不知道如何运行脚本)。脚本以通常的方式进入header.php,但没有结果

例如,我的主页上的所有“Shop”实例(在菜单中,h2元素,在Wordpress内容中)保持不变,尽管有这个脚本

$("span, p, div").each(function() {
    var text = $(this).text();
    text = text.replace("Shop", "Sale");
    $(this).text(text);
});
有什么想法吗

我已禁用缓存插件,但没有任何效果

提前谢谢

更新

全部我有

<script type="text/javascript">
    $(document).ready(function(){
        $("span, p, div").each(function() {
        var text = $(this).text();
        text = text.replace("type", "typo");
        $(this).text(text);
    });
</script>

$(文档).ready(函数(){
$(“span,p,div”)。每个(函数(){
var text=$(this.text();
text=text.replace(“type”,“typo”);
$(此).text(文本);
});

仍然没有乐趣。

如果你在网站上执行这样的代码,它会在你的html中造成混乱……不要这样做:)

改为这样做:

$("span, p, div").each(function() {
    var text = $(this).html();
    text = text.replace("Shop", "Sale");
    $(this).html(text);
});

如果你在你的网站上执行这样的代码,它会在你的html中造成混乱…不要这样做:)

改为这样做:

$("span, p, div").each(function() {
    var text = $(this).html();
    text = text.replace("Shop", "Sale");
    $(this).html(text);
});

使用此代码,您将很高兴

<script type="text/javascript">
    $(document).ready(function(){
    var replaced = $("body").html().replace('Shop','Sale');
    $("body").html(replaced);
    });
</script>

$(文档).ready(函数(){
var replaced=$(“body”).html().replace('Shop','Sale');
$(“正文”).html(已替换);
});

使用此代码,您将很高兴

<script type="text/javascript">
    $(document).ready(function(){
    var replaced = $("body").html().replace('Shop','Sale');
    $("body").html(replaced);
    });
</script>

$(文档).ready(函数(){
var replaced=$(“body”).html().replace('Shop','Sale');
$(“正文”).html(已替换);
});

您需要在document ready中调用此函数,并使用regex替换所有实例:

$(function(){
    $("span, p, div").each(function() {
        var text = $(this).text();
        text = text.replace(/Shop/g, "Sale"); // regex instead of string
        $(this).text(text);
    });
});

您需要在document ready中调用此函数,并使用正则表达式替换所有实例:

$(function(){
    $("span, p, div").each(function() {
        var text = $(this).text();
        text = text.replace(/Shop/g, "Sale"); // regex instead of string
        $(this).text(text);
    });
});

只需在控制台中打印值。只需检查您是否在控制台中获得值。您的脚本在
document.ready
中的何处?您是否在document ready
$(function(){…});
text=text.replace(新的RegExp(“Shop”,“g”),“Sale”)中调用了该脚本
只需在控制台中打印值。只需检查您是否在控制台中获得值。您的脚本在
文档中的何处。就绪
?您是否在document ready
$(function(){…});
text=text.replace(新的RegExp(“Shop”,“g”),“Sale”)就是那个。谢谢。就是那个。谢谢。