Je cette response.write sur ma pagejavascript document.write casser ma page
function roundthecon() {
document.write(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2));
}
Mais il est réécrivant ma page entière et de le remplacer par le nombre arrondi est-il une autre façon de le faire sans ré-écrire ma page?
Merci
Jamie
MISE À JOUR
javascript de la pleine
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("€");
}
var o_span = $('<span/>').html(' <span style="font-weight:normal;" id="exchRate">(£' + v_pound + ')</span>');
$(this).append(o_span);
}
});
});
}
Il est toujours de bons conseils pour éviter document.write si possible, comme les autres réponses suggèrent, mais néanmoins il doit y avoir quelque chose d'autre ne va pas ici. document.write() est explicitement défini pour arrêter le rendu de la page et écrire son contenu directement après le bloc de script qui l'appelle, puis poursuivre le rendu. Vous devez faire quelque chose qui casse ce comportement - d'où appelez-vous roundthecon()? – AHM