2010-03-11 46 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>");