SCRIPT5007:该对象专门在IE浏览器上使用

时间:2019-04-04 09:56:36

标签: javascript jquery internet-explorer

我尝试使用以下代码运行脚本。这似乎可以在Chrome,Firefox,Opera,Edge和Brave上使用。我似乎无法使其与Internet Explorer 11或更低版本一起使用。

最初,当我创建脚本时,app.js中的函数是这样格式化的

function x() {
  fetch('example.domain')
    .then(blob => blob.json())
    .then(data => obj = data)
    .then(function(y) {

然后我发现IE不支持=>运算符,并将此代码重构为

function x() {
  fetch('example.domain').then(function (blob) {
    return blob.json();
  }).then(function (data) {
    return obj = data;
  }).then(function (y) {

此代码现在似乎工作正常。现在,问题已移至index.html,我试图在该页面上显示jQuery datepicker元素。代码的格式如下

  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
  <script src="app.js"></script>
</head>
<body>
  <script>
    $(document).on('change', 'select', function () {
      if ($("#datepicker").datepicker("getDate") === null) {
        alert("You have not selected a date.");
      } else {
        x();
      }
    });

    $("#datepicker").show();

    $(function () {
      $('#datepicker').datepicker({
        onSelect: y,
        dateFormat: 'yy-mm-dd'
      });
    });
  </script>

出现错误的地方

  

SCRIPT5007:对象预期为index.html,第8行字符1

专注于行

$(document).on('change', 'select', function () {

我已经研究了jQuery的使用,它已经被导入一次。我已经对照ES6验证器检查了脚本,似乎还可以。 jQuery是否使用了IE浏览器不支持的功能,或者我的代码格式完全错误?

1 个答案:

答案 0 :(得分:0)

在阅读Rory McCrossan的评论后,我实现了this polyfill。这使我可以在IE中使用fetch()函数。无需对代码进行其他更改。