2010-03-11 43 views
1

我是一个新的访问者,并且在jQuery中相对较新。在图像上复制并操作ALT

我有,我想显示,在SPAN,图像下方,并操纵,以取代ALT文字图像“ - ”用B和I-标签...

电流HTML:

<span class="alignright"> 
    <img src="sys/billeder/medarbejdere/tommy_stor.jpg" width="162" height="219" title="Name - Age" /> 
    <span></span> 
</span> 

通缉输出

<span class="alignright"> 
    <img src="sys/billeder/medarbejdere/tommy_stor.jpg" width="162" height="219" title="Name - Age" /> 
    <span><b>Name</b> <i>Age</i></span> 
</span> 

我已经使用这个jQuery来提取ALT,并把它放在SPAN:

var alt = $("#hoejre p span img").attr("alt"); 
$("#hoejre p span span").text(alt); 

提取工程就像一个魅力,但我需要的SPAN:

...to start with "<b>" 
...to replace the "-" with "</b> <i>" 
...and end with "</i>" 

回答

1

不知道如果我没有理解错的,但如何改变你的最后一行:

$("#hoejre p span span").html("<b>" + alt.replace("-", "</b> <i>") + "</i>"); 
+0

这就像一个魅力 - 谢谢你... – 2010-03-11 12:25:31

0

这个怎么样:

$("#hoejre p span span").html('<b>'+alt.replace('-', '</b> <i>')+'</i>'); 

replace仅仅是常规的JavaScript,html() jQuery的方法(documented here)。

0
var alt = $("#hoejre p span img").attr("alt"); 
$("#hoejre p span span").html("<b>"+alt.replace("-", "</b><i>")+"</i>");