2010-04-29 15 views
5

Gradirei un aiuto con base a una condizione, vorrebbe sostituire il seguente blocco HTML:Come sostituire un blocco di HTML con un altro blocco di codice HTML utilizzando jQuery

<table class="t12PageBody" cellpadding="0" cellspacing="0" width="100%" summary=""> 
    <tr><td colspan="2">#REGION_POSITION_01#</td></tr> 
</table> 

<table width="100%" summary=""> 
<tr> 
    <td class="t12ContentBody" valign="top"> #SUCCESS_MESSAGE# #NOTIFICATION_MESSAGE# #BOX_BODY# #REGION_POSITION_04##REGION_POSITION_05##REGION_POSITION_06##REGION_POSITION_07##REGION_POSITION_08#</td> 
    <td align="right" valign="top" class="t12ContentBody">#REGION_POSITION_03#<br /></td> 
</tr> 
</table> 

con questo blocco:

<div id = "banner"> 
<div class="Logo"></div> 
<img src="http://www.abc.com/home/images/spacer.gif" height="35" width="180" border="0" alt=""> <font class="bannertext">&APPNAME.</font> 
<div class="bannerText"> 
    <div class="hmenu"><ul>&APPLICATION_LINKS.</ul></div> 
</div> 

ho guardato la funzione di sostituzione in jQuery ma non siete sicuri come applicare.

Grazie.

risposta

13
var newHTML = '<div id = "banner"><div class="Logo"></div>' + 
       '<img src="http://www.abc.com/home/images/spacer.gif" ' + 
       'height="35" width="180" border="0" alt=""> <font ' + 
       'class="bannertext">&APPNAME.</font><div class="bannerText">' + 
       '<div class="hmenu"><ul>&APPLICATION_LINKS.</ul>' + 
       '</div></div>'; 
$('table.t12PageBody').replaceWith(newHTML); 
+0

@Matthew è possibile riformattare la voce? rompere le linee a parte o qualcosa per renderlo più leggibile? – BerggreenDK

+0

@BerggreenDK L'ho diviso in più stringhe concatenate. –

+0

Grazie Matteo e tutto ciò che ha risposto - tutto bene. – tonyf

0

Se si dispone di un wrapper per cui si desidera mettere, utilizzare .html(...)

$('#wrapper').html('<div id = "banner">' + ...); 
+1

E 'più facile solo per utilizzare la funzione di 'replaceWith' in questo caso. –

Problemi correlati