Javascript jQuery搜索和替换不工作(Wordpress)
我一定试过半打脚本(大多数都在这里找到,例如at)来替换Wordpress构建站点()上的文本 没用。我不够聪明,不知道为什么(但也不够愚蠢,不知道如何运行脚本)。脚本以通常的方式进入header.php,但没有结果 例如,我的主页上的所有“Shop”实例(在菜单中,h2元素,在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
$("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”)就是那个。谢谢。就是那个。谢谢。