2012-11-12 44 views
1

我需要添加图片标签到WP电子商务的自定义元字段,但是当我添加它时,它将其作为文本拉出。我想使用jQuery,因此查找和替换<>括号,以便它,而不是渲染为一个标签。找到< <使用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;到<和&gt;以正确的方式> ?

谢谢。

+1

只是一个提示:'的jQuery(函数($){/ *现在使用$自由* /});' –

回答

1

这应该这样做

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

更多的documentation about .html()

+0

由于加比!这就是诀窍! – SixfootJames

相关问题