找到<到<使用jQuery

时间:2012-11-12 13:38:11

标签: jquery replace

我需要在WP电子商务的自定义元字段中添加图片标签,但是当我添加它时,它会将其作为文本拉出来。我想使用Jquery来查找和替换< >括号,以便它作为标记呈现。

这是我的源代码:

<div class="custom_meta">
<strong>CODE: </strong>JL16<br>
<strong>Colour: </strong>&lt;img src="http://localhost:81/live_products/shop/wp-content/uploads/blue.gif" /&gt;<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(/&lt;/g, '<');
    jQuery(".custom_meta").replace(/&gt;/g, '>');

});

这是将&lt;替换为&lt; {1}}的正确方法吗?和&gt;到&gt; ?

谢谢。

1 个答案:

答案 0 :(得分:1)

这应该这样做

jQuery(".product_description").html(function(i, currenthtml){
   return currenthtml.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
});

documentation about .html()

了解详情