简体   繁体   English

JS 在 IE 上无法正常运行,但在 Chrome 中运行完美

[英]JS isn't working correctly on IE but works perfect in Chrome

I'm trying to create a JS that print out today's date, it's working perfectly with Chrome but it's not on Internet Explorer.我正在尝试创建一个打印出今天日期的 JS,它与 Chrome 完美配合,但不在 Internet Explorer 上。

I'm not sure what JS function is not available on Internet Explorer?我不确定 Internet Explorer 上没有什么 JS function? My facility is still default to Internet Explorer for some reasons and it's extremely frustrating trying to find a work around.由于某些原因,我的设备仍然默认使用 Internet Explorer,并且尝试找到解决方法非常令人沮丧。

//get today's date & month
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const date = today.getDate();

//get day of the week
  var weekday = new Array(7);
  weekday[0] = "Sunday";
  weekday[1] = "Monday";
  weekday[2] = "Tuesday";
  weekday[3] = "Wednesday";
  weekday[4] = "Thursday";
  weekday[5] = "Friday";
  weekday[6] = "Saturday";
  var dayOfWeek = weekday[today.getDay()];
const todayDate = month+ "/"+ date + "/" + year;
document.querySelector(".dayOfWeek").innerHTML= dayOfWeek ;
document.querySelector(".sdDate").innerHTML= todayDate;

//get present's month
var monthOfYear = new Array(12);
  monthOfYear[1] = "January";
  monthOfYear[2] = "February";
  monthOfYear[3] = "March";
  monthOfYear[4] = "April";
  monthOfYear[5] = "May";
  monthOfYear[6] = "June";
  monthOfYear[7] = "July";
  monthOfYear[8] = "August";
  monthOfYear[9] = "September";
  monthOfYear[10] = "October";
  monthOfYear[11] = "November";
  monthOfYear[12] = "December";
  var monthOfYearprt = monthOfYear[month];
  document.querySelector(".bdMonth").innerHTML= monthOfYearprt;

  
<div id="specialDay">
            <div class="todayDate">
              <span class="dayOfWeek"></span>
              <br>
              <span class="sdDate"></span>
            </div>
           
          
        </div>

Try declaring your vars with var instead of const .尝试使用var而不是const声明您的 var。

As it stands, const is not widely supported by IE .就目前而言, const 并未得到 IE 的广泛支持

Basically, if you're testing IE outside of IE11 then your code may not work as expected.基本上,如果您在IE11之外测试 IE,那么您的代码可能无法按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [0].submit 不适用于 IE 和 Firefox,在 Chrome 中完美运行 - [0].submit not working in IE and Firefox, works perfect in Chrome Javascript在Firefox / IE中不起作用,但在Chrome中有效 - Javascript isn't working in Firefox/IE but works in Chrome Javascript / AJAX无法在Opera中运行,在FF / IE / Chrome中可以完美运行 - Javascript/AJAX not working in Opera, works perfect in FF/IE/Chrome JS在Firefox中无法使用,在IE和Chrome中可以使用 - JS not working in Firefox, works in IE and Chrome 正则表达式无法正确识别IE版本 - Regex isn't working correctly to identity IE version DirectLineJS在FireFox中不起作用,在Edge和Chrome中工作 - DirectLineJS isn't working in FireFox, works in Edge and Chrome .pause() 在 Chrome 和 Firefox 中不起作用,但在 Safari 中工作正常 - .pause() isn't working in Chrome & Firefox, but works fine in Safari 名为 `animate` 的 JS 函数在 Chrome 中不起作用,但在 IE 中起作用 - JS function named `animate` doesn't work in Chrome, but works in IE JS正则表达式代码不适用于Firefox,但适用于Chrome和IE - JS regex code doesn't work with firefox, but works on chrome and IE Javascript可在JS Fiddle中使用,但不适用于Chrome / IE - Javascript works in JS Fiddle but doesn't work in Chrome/IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM