2010-09-29 9 views
1

Voici mon problème, j'ai ce javascriptjavascript append apparaissant deux fois

if (exchRate != "") { 

function roundthecon() { 
var value = Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2); 
$('.tablenotes > p > strong ').append(value); 
} 

function addCommas(nStr) { 
nStr += ''; 
x = nStr.split('.'); 
x1 = x[0]; 
x2 = x.length > 1 ? '.' + x[1] : ''; 
var rgx = /(\d+)(\d{3})/; 
while (rgx.test(x1)) { 
x1 = x1.replace(rgx, '$1' + ',' + '$2'); 
} 

return x1 + x2; 
} 


     // When the document is loaded.. 
     $(document).ready(function(){ 


       // Grab an array of the table cells 
       $('.evenprop table tr td:not(.title)').each(function(){ 

         // Calculate the pound price 
         var v_euro = $(this).html(); 

         if (v_euro != "N/A") { 

         var v_euro = v_euro.replace(/,/g,''); 
         var v_euro = v_euro.replace(/\u20AC/g, ''); 
         var v_euro = v_euro.replace(/£/g, ''); 

         var v_pound = Math.round(v_euro/exchRate); 
         v_pound = addCommas(v_pound); 

         // Create a new span element for the pound 


         // Insert it at the end of the table cell 

         if (exchRate == <%= Session("xch_dollar") %>) { 
         $(this).prepend("$"); 
         } 
         if (exchRate == <%= Session("xch_ntl") %>) { 
         $(this).prepend("X"); 
         } 
         if (exchRate == <%= Session("xch_euro") %>) { 
         $(this).append("&euro;"); 
         } 

         var o_span = $('<span/>').html(' <span style="font-weight:normal;" id="exchRate">(&pound;' + v_pound + ')</span>'); 
         $(this).append(o_span); 

         } 
       }); 

     }); 

     } 

Et voici mon code HTML dans la page

<div class="tablenotes"> 

<p><span class="tariffnote">Weekly price in Euros.</span> &pound; in brackets are approximate sterling equivalent based on <strong>&pound;1 = 
    <script type="text/javascript">roundthecon()</script><noscript><%= Session("xch_euro") %></noscript>&euro;</strong> </p> 


</div> 

Et le exchRate = 1.1986 pour quelque raison que mon code est à l'affiche.

<div class="tablenotes"> 

<p><span class="tariffnote">Weekly price in Euros.</span> £ in brackets are approximate sterling equivalent based on <strong>£1 = 
    1.2<noscript>1.1986</noscript>€1.2</strong> </p> 


</div> 

Il est Franchir le exchRate comme il se doit, mais il est de le placer dans deux

Quelqu'un at-il des idées?

Merci

Jamie

+0

Pourriez-vous s'il vous plaît préciser ce qui est placé deux fois ? –

Répondre

0

j'ai eu autour de la question en faisant cette

$(document).ready(function(){ 
    var value = Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2); 
    $('.tablenotes > p > strong ').html("&pound;1 = " + value + "&euro;"); 
}); 

Il remplace l'ensemble html plutôt que annexant