JavaScript代码在IE 10中不起作用

时间:2017-12-23 23:03:32

标签: javascript internet-explorer internet-explorer-10

我编写的代码可以计算预订的价格。此代码适用于Chrome,Firefox,Edge ......但它在IE(10)中不起作用。它根本不会触发,因为即使是一开始就没有显示警报。我已经允许DirectX并且还将安全性设置为安全选项中可能的最低选项。我不知道这可能是什么原因。

要进行实时测试,请填写表单的第一页,在第二页上,一旦您选择到达日期和出发日期,就应该触发脚本:https://www.vakantiehuislesforges.com/reserveren-stap1/

这是触发它的事件:

<input type="text" name="aankomstdatum" id="aankomstdatum" onchange="aankomstdatumInput();berekenPrijs()">

这是JavaScript代码:

var aankomstDatumDate;
var vertrekDatumDate;
var spans;
var totaalPersonen;

alert("IE test");

//Get arrival date from datepicker + aantal kinderen & volwassenen
function aankomstdatumInput() {
var aankomstDatum = document.getElementById("aankomstdatum").value;
//alert(aankomstDatum);
document.getElementById("aankomst").innerHTML = aankomstDatum;
var parts = aankomstDatum.split('-');
aankomstDatumDate = new Date(parts[2],parts[1]-1,parts[0]);
//alert(aankomstDatumDate);
document.getElementById("aankomstDate").innerHTML = aankomstDatumDate;
//get aantal kinderen en volwassenen
spans = document.querySelectorAll('#aantallen span');
totaalPersonen = Array.from(spans).reduce((sum, spanElm) => sum + Number(spanElm.textContent), 0);
//alert(totaalPersonen);
}

//Get departure date from datepicker
function vertrekdatumInput() {
vertrekDatum = document.getElementById("vertrekdatum").value;
//alert(vertrekDatum);
document.getElementById("vertrek").innerHTML = vertrekDatum;
var parts2 = vertrekDatum.split('-');
vertrekDatumDate = new Date(parts2[2],parts2[1]-1,parts2[0]);
document.getElementById("vertrekDate").innerHTML = vertrekDatumDate;
}

//fire function onchange and get the arrival date and departure date and make the array
function berekenPrijs() {
//var aankomst = new Date("November 25, 2017");
//var vertrek = new Date("December 2, 2017");
//alert(aankomstDatumDate);
//alert(vertrekDatumDate);
//alert(aankomst);
var maand = aankomstDatumDate.getMonth();
var verblijfDagen = [];
var day = 1000*60*60*24;
var diff = (vertrekDatumDate.getTime()- aankomstDatumDate.getTime())/day;

//calculate all seperate days from arrival date to departure date and put them in an array   
for(var i=0;i<=diff; i++)
{
   var xx = aankomstDatumDate.getTime()+day*i;
   var yy = new Date(xx);
   var zz = (yy.getDate()+"-"+(yy.getMonth()+1)+"-"+yy.getFullYear());
   var parts = zz.split('-');
   var zzDate = new Date(parts[2],parts[1]-1,parts[0]);
   //check if this date is a saturday and in the correct Date structure && zzDate mag niet gelijk zijn aan vertrekdatum of laatst
   if(zzDate.getDay() === 0) verblijfDagen.push(zzDate);
   //alert(verblijfDagen);
}
//check if all the days are in the array
//alert (verblijfDagen);

//declare the period of the different seasons and the daily cost rate during this season 
var December2019 = {startDate: new Date(2019,12-1,1), endDate: new Date(2019,12-1,31), costRate: 550};
var November2019 = {startDate: new Date(2019,11-1,1), endDate: new Date(2019,11-1,30), costRate: 550};
var Oktober2019 = {startDate: new Date(2019,10-1,1), endDate: new Date(2019,10-1,31), costRate: 690};
var September2019 = {startDate: new Date(2019,9-1,1), endDate: new Date(2019,9-1,30), costRate: 1190};
var Augustus2019 = {startDate: new Date(2019,8-1,1), endDate: new Date(2019,8-1,31), costRate: 1690};
var Juli2019 = {startDate: new Date(2019,7-1,1), endDate: new Date(2019,7-1,31), costRate: 1690};
var Juni2019 = {startDate: new Date(2019,6-1,1), endDate: new Date(2019,6-1,30), costRate: 1190};
var MeiEind2019 = {startDate: new Date(2019,5-1,15), endDate: new Date(2019,5-1,31), costRate: 1190};
var MeiBegin2019 = {startDate: new Date(2019,5-1,1), endDate: new Date(2019,-1,14), costRate: 840};
var April2019 = {startDate: new Date(2019,4-1,1), endDate: new Date(2019,4-1,30), costRate: 750};
var Maart2019 = {startDate: new Date(2019,3-1,1), endDate: new Date(2019,3-1,31), costRate: 550};
var Februari2019 = {startDate: new Date(2019,2-1,1), endDate: new Date(2019,2-1,30), costRate: 550};
var Januari2019 = {startDate: new Date(2019,1-1,1), endDate: new Date(2019,1-1,31), costRate: 550};
var December2018 = {startDate: new Date(2018,12-1,1), endDate: new Date(2018,12-1,31), costRate: 550};
var November2018 = {startDate: new Date(2018,11-1,1), endDate: new Date(2018,11-1,30), costRate: 550};
var Oktober2018 = {startDate: new Date(2018,10-1,1), endDate: new Date(2018,10-1,31), costRate: 690};
var September2018 = {startDate: new Date(2018,9-1,1), endDate: new Date(2018,9-1,30), costRate: 1190};
var Augustus2018 = {startDate: new Date(2018,8-1,1), endDate: new Date(2018,8-1,31), costRate: 1690};
var Juli2018 = {startDate: new Date(2018,7-1,1), endDate: new Date(2018,7-1,31), costRate: 1690};
var Juni2018 = {startDate: new Date(2018,6-1,1), endDate: new Date(2018,6-1,30), costRate: 1190};
var MeiEind2018 = {startDate: new Date(2018,5-1,15), endDate: new Date(2018,5-1,31), costRate: 1190};
var MeiBegin2018 = {startDate: new Date(2018,5-1,1), endDate: new Date(2018,-1,14), costRate: 840};
var April2018 = {startDate: new Date(2018,4-1,1), endDate: new Date(2018,4-1,30), costRate: 750};
var Maart2018 = {startDate: new Date(2018,3-1,1), endDate: new Date(2018,3-1,31), costRate: 550};
var Februari2018 = {startDate: new Date(2018,2-1,1), endDate: new Date(2018,2-1,30), costRate: 550};
var Januari2018 = {startDate: new Date(2018,1-1,1), endDate: new Date(2018,1-1,31), costRate: 550};
var December2017 = {startDate: new Date(2017,12-1,1), endDate: new Date(2017,12-1,31), costRate: 550};
var November2017 = {startDate: new Date(2017,11-1,1), endDate: new Date(2017,11-1,30), costRate: 550};
var allSeasons = [November2017, December2017, Januari2018, Februari2018, Maart2018, April2018, MeiBegin2018, MeiEind2018, Juni2018, Juli2018, Augustus2018, September2018, Oktober2018, November2018, December2018, Januari2019, Februari2019, Maart2019, April2019, MeiBegin2019, MeiEind2019, Juni2019, Juli2019, Augustus2019, September2019, Oktober2019, November2019, December2019];
//check if this date is in the correct Date structure
//alert(November2017.startDate instanceof Date);
//check if the date is correct
//alert (November2017.startDate);

var totalPrice = 0;
for (var u = 0; u < verblijfDagen.length; u++) {
   for(var j = 0; j < allSeasons.length; j++) {
    if (verblijfDagen[u] >= allSeasons[j].startDate && verblijfDagen[u] <= allSeasons[j].endDate) {
      //Add costRate of this date to totalPrice
      totalPrice = totalPrice + allSeasons[j].costRate;
    }
  }
}

var totalPriceFinal = totalPrice + (totaalPersonen*10);
var totalVoorschot = totalPriceFinal/100*50;
var totalRestBedrag = totalPriceFinal/100*50;
//alert (totalVoorschot);
//alert (totalRestbedrag);

document.getElementById("totaalPrijsLabel").innerHTML = totalPriceFinal;
document.getElementById("totaalPrijs").value = totalPriceFinal;
document.getElementById("totaalVoorschot").value = totalVoorschot;
document.getElementById("totaalRestbedrag").value = totalRestbedrag;
};

感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

我猜你的ECMA 6 arrow在IE10上不受支持,在这一行:

Array.from(spans).reduce((sum, spanElm) => sum + Number(spanElm.textContent), 0);