IE11抛出“SCRIPT1014:无效字符”所有其他浏览器都可以使用 [英] IE11 throwing "SCRIPT1014: invalid character" where all other browsers work

查看:8889
本文介绍了IE11抛出“SCRIPT1014:无效字符”所有其他浏览器都可以使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个新的,IE11在每个其他浏览器中运行的代码上抛出错误。

Here's a new one, IE11 is throwing errors on code that works in every other browser.

无论如何,经过几个小时的修复代码以便IE11不会自行落后我遇到了一个错误,我似乎无法找到一个解决方案。以下是有问题的代码:

Anyway, after a few hours of "fixing" code so that IE11 doesn't fall on its own face I have come across an error I just cannot seem to find a solution to. Here is the code in question:

$('input[name="messageAccount"]').change(function () {
    $aButton.show();
    var addedIds = $("#hdnfield").val();
    if (addedIds == null || addedIds === "") {
        $("#hdnfield").val(this.value);
    } else {
        $("#hdnfield").val(`${addedIds}${this.value}`);
    };
});

这是嵌套在Ajax请求中成功调用的内部。 IE的调试器说这个错误来自 else 语句的内容,但是它也读错了所有的括号。例如,在Ajax请求的结束括号之后,此函数的左括号正在关闭...(希望这是有意义的)。

This is nested on the inside of the success call in an Ajax request. IE's debugger is saying the error is coming from the content of the else statement but it's also reading all the brackets wrong. For example the opening parenthesis on this function is being "closed" after the closing bracket for the Ajax request... (hopefully that made sense).

以前有没有其他人遇到过与IE类似的问题?我还有其他一些错误要解决,所以如果有任何回复,我会尽快回复。在此先感谢。

Has anyone else had a similar issue with IE before? I've got a number of other bugs to fix so if there are any replies I will post back as soon as I can. Thanks in advance.

编辑:仅供参考我目前正在本地运行,并且将成为内部托管的网络应用程序的一部分。

just for reference I am currently running this locally and is part of what will become an internally hosted web app.

推荐答案

这是因为IE不支持`(模板字符串): http://caniuse.com/#search=string

It's because "`" (template strings) is not supported by IE : http://caniuse.com/#search=string

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

请参阅 https://stackoverflow.com/a/27678299/2195875

为避免此错误,您可以使用ES6到ES5转发器,也可以直接写有效的ES5 javascript:

To avoid this error you can either use a ES6 to ES5 transpiler, or just directly write valid ES5 javascript:

而不是


`string text $ {expression} string text`

`string text ${expression} string text`


string text+ expression +string text

"string text "+expression+" string text"

这篇关于IE11抛出“SCRIPT1014:无效字符”所有其他浏览器都可以使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆