gpt4 book ai didi

javascript document.write 破坏了我的页面

转载 作者:行者123 更新时间:2023-11-30 10:53:33 27 4
gpt4 key购买 nike

我的页面上有这个 response.write

function roundthecon() {
document.write(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2));
}

但它正在重写我的整个页面并将其替换为四舍五入的数字是否有任何其他方法可以在不重写我的页面的情况下执行此操作?

谢谢

杰米

更新

完整的javascript

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);

}
});

});

}

最佳答案

function roundthecon() {
var value = Math.round(exchRate*Math.pow(10,2)) / Math.pow(10,2);
$('#some_element_id').text(value);
}

document.write 通常最好不要使用。它可以做一些奇怪的事情。

关于javascript document.write 破坏了我的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3815091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com