我的代码不起作用,我不知道为什么??我有Wordpress。
一个Wordpress插件将一些代码从外部站点注入到我的wordpress站点中。
该代码从外部网站加载并在我的wordpress网站上显示了一些难看的图像。所以我想用我自己的图像替换丑陋的图像。我无法从外部站点编辑HTML代码。

这是我插入到footer.php中的代码。

<script type="text/javascript">
jQuery(document).ready(function() {
 var the_image_source = "http://original.xyz/original.png";
var new_src = "/wp-content/images/myone.png";
jQuery('img[src=' + the_image_source + ']').attr('src',new_src);
    });
</script>


我不知道怎么了,请帮帮我!谢谢!

最佳答案

如果在选择器中添加双引号,它将起作用:

jQuery(document).ready(function () {
    var the_image_source = "http://original.xyz/original.png";
    var new_src = "/wp-content/images/myone.png";
    jQuery('img[src="' + the_image_source + '"]').attr('src', new_src);
//                  ^                        ^
});


演示here

08-05 04:17
查看更多