gpt4 book ai didi

JavaScript 函数无法在 Chrome 和 IE 上运行,但可以在 FireFox 上运行

转载 作者:行者123 更新时间:2023-11-28 19:34:18 24 4
gpt4 key购买 nike

最近我开发了一个有很多实时计算选项的系统。我已经在 Firefox 上测试了这些功能,但是当我尝试在 Chorme 中运行这个程序时,它不起作用。它没有显示结果

function premiumCalculation(){

var shortPeriodRate = 100;
var spr = document.getElementById("policyPeriod");
shortPeriodRate = parseInt(spr.options[spr.selectedIndex].value);
var shortPeriodDate = spr.options[ spr.selectedIndex ].text;
//================== hidden assign ======================================================
document.getElementById("policyPeriodInput").value = spr.options[spr.selectedIndex].text;
//=======================================================================================

var sumInsured = document.getElementById("sumInsuredValue").value;
var basicRate = document.getElementById("basicRate").value;
var srcc = document.getElementById("srccRateInput").value;
var tc = document.getElementById("tcRateInput").value;

//============================= BASIC PREMIUM CALCULATION ==========================================
var shortPrecentage = parseFloat(shortPeriodRate) / 100;
var basicPremium = ((parseFloat(sumInsured) * parseFloat(basicRate)) * parseFloat(shortPrecentage)/100);
if(basicPremium < 500){basicPremium = 500;}
document.getElementById("basicPremium").innerHTML = money_format(basicPremium);
document.getElementById("basicPremiumInput").value = basicPremium;
//===================================================================================================


var currentDate = new Date();
var nextDate = '';

var spd = shortPeriodDate.split(" ");
var spdDate = spd[0];

//================ FOR 3 & 10 DAYS ===============================
if(shortPeriodRate == 5 || shortPeriodRate == 10){
var month = currentDate.getMonth()+ 1;
var day = currentDate.getDate() + parseFloat(spdDate);
var year = currentDate.getFullYear();
if(month < 10){ month = "0" + month;}
nextDate = (year + '/' + month + '/' + day);
nextDate = new Date(nextDate);
nextDate = nextDate.toLocaleFormat('%Y-%m-%d');
}
//================================================================
//================ FOR Months ==============================================
if(shortPeriodRate != 5 && shortPeriodRate != 10 && shortPeriodRate != 25){
var month = (currentDate.getMonth()+ 1) + parseFloat(spdDate);
var day = currentDate.getDate();
var year = currentDate.getFullYear();
if(month < 10){ month = "0" + month;}
nextDate = (year + '/' + month + '/' + day);
nextDate = new Date(nextDate);
nextDate = nextDate.toLocaleFormat('%Y-%m-%d');
}
//===========================================================================
//========================= DATE DIFFERENCE ==========================================
var oneDay = 24*60*60*1000;
var firstDate = new Date(currentDate);
var secondDate = new Date(nextDate);
var dateDifference = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
dateDifference = Math.round(dateDifference);
//====================================================================================
//===================== SRCC PREMIUM CALCULATION ==============================================
var srccLogic = document.getElementById('strikeRiot').value; //alert(srccLogic);
if(srccLogic == 'yes'){
var srccPrecentage = parseFloat(dateDifference) / 365;
var srccPremium = (parseFloat(sumInsured) * parseFloat(srcc) * parseFloat(srccPrecentage)/100);
document.getElementById("srccPremium").innerHTML = money_format(srccPremium);
document.getElementById("srccPremiumInput").value = srccPremium;
} else {
srccPremium = 0;
srccPrecentage = 1;
document.getElementById("srccPremium").innerHTML = money_format(srccPremium);
document.getElementById("srccPremiumInput").value = srccPremium;
}
//=============================================================================================
//========================= TC PREMIUM CALCULATION ==========================================
var tcLogic = document.getElementById('terrorism').value; //alert(srccLogic);
if(tcLogic == 'yes'){
var tcPrecentage = parseFloat(dateDifference) / 365;
var tcPremium = (parseFloat(sumInsured) * parseFloat(tc) * parseFloat(tcPrecentage)/100);
document.getElementById("tcPremium").innerHTML = money_format(tcPremium);
document.getElementById("tcPremiumInput").value = tcPremium;
} else {
tcPremium = 0;
tcPrecentage = 1;
document.getElementById("tcPremium").innerHTML = money_format(tcPremium);
document.getElementById("tcPremiumInput").value = tcPremium;
}
//===========================================================================================
//==================== ADMIN FEE CALCULATION =======================================
var adminFeeTotal = basicPremium + srccPremium + tcPremium;
var adminFee = (parseFloat(adminFeeTotal) * 0.3) / 100 ;
document.getElementById("adminFee").innerHTML = money_format(adminFee);
document.getElementById("adminFeeInput").value = adminFee;
//==================================================================================
//================== POLICY FEE======================================
document.getElementById("policyFee").innerHTML = "450.00";
document.getElementById("policyFeeInput").value = "450";
//===================================================================
//================== STAMPFEE CALCULATION ===========================
var totalUp = parseFloat(basicPremium) + parseFloat(srccPremium) + parseFloat(tcPremium) + parseFloat(adminFee) + parseFloat(450);
var stampFee = Math.round((totalUp * 0.1) / 100);
var stampFeeS = (totalUp * 0.1) / 100;
var roundUpString = stampFeeS.toString();
var roundUpVal = roundUpString.split(".");
var roundUpValT = roundUpVal[1]; var roundUpValTV = parseFloat(roundUpValT);
//if(roundUpValTV > 0){ stampFee = stampFee + 1;}
document.getElementById("stampFee").innerHTML = money_format(stampFee);
document.getElementById("stampFeInput").value = stampFee;
//================================================================================
//================= NBT CALCULATION ==============================================
var nbtPremium = ((totalUp * 2) / 98);
document.getElementById("nbt").innerHTML = money_format(nbtPremium);
document.getElementById("nbtInput").value = nbtPremium;
//================================================================================
//================ VAT CALCULATION ===============================================
var totalForVAT = parseFloat(totalUp) + parseFloat(nbtPremium);
var VATPremium = ((totalForVAT * 12) / 100);
document.getElementById("vat").innerHTML = money_format(VATPremium);
document.getElementById("vatInput").value = VATPremium;
//================================================================================
//=============== GROSS CALCULATION ================
var grossPremium = parseFloat(totalForVAT) + parseFloat(stampFee);
document.getElementById("grossPremium").innerHTML = money_format(grossPremium);
document.getElementById("grossPremiumInput").value = grossPremium;
//==================================================
//=============== NETPREMIUM CALCULATION ===========
var netPremium = parseFloat(grossPremium) + parseFloat(VATPremium);
document.getElementById("netPremium").innerHTML = money_format(netPremium);
document.getElementById("netPremiumInput").value = netPremium;
//==================================================

}

enter image description here enter image description here

最佳答案

根据您的起始主题中的评论,您可以简单地检测/重写缺少的函数:

Date.prototype.toLocaleFormat = Date.prototype.toLocaleFormat || function(pattern) {
return pattern.replace(/%Y/g, this.getFullYear()).replace(/%m/g, (this.getMonth() + 1)).replace(/%d/g, this.getDate());
};

重写将在全局范围内可用,您可以使用此 jsfiddle 来测试它

关于JavaScript 函数无法在 Chrome 和 IE 上运行,但可以在 FireFox 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26212920/

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