我需要在WP电子商务的自定义元字段中添加图片标签,但是当我添加它时,它会将其作为文本拉出来。我想使用Jquery来查找和替换< >括号,以便它作为标记呈现。
这是我的源代码:
<div class="custom_meta">
<strong>CODE: </strong>JL16<br>
<strong>Colour: </strong><img src="http://localhost:81/live_products/shop/wp-content/uploads/blue.gif" /><br>
<strong>COLOURS: </strong>BLACK, WHITE, GREY, CORAL, BLUE<br>
<strong>FABRIC: </strong>LYCRA<br>
</div>
以下是我认为它应该在jQuery中工作的方式:
jQuery(document).ready(function(){
// Remove "" from meta image
jQuery(".custom_meta").replace(/</g, '<');
jQuery(".custom_meta").replace(/>/g, '>');
});
这是将<
替换为&lt; {1}}的正确方法吗?和>
到&gt;
?
谢谢。
答案 0 :(得分:1)
这应该这样做
jQuery(".product_description").html(function(i, currenthtml){
return currenthtml.replace(/</g, '<').replace(/>/g, '>');
});
了解详情