admin管理员组文章数量:1287080
I'm using a long HTML Template script in JS file, like:
var TEMPLATE = `
<div>
<ul>
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
</div>`;
It works in all browsers(including Chrome, Safari, Firefox & EDGE) but not in Internet Explorer 11, 10.
Can you suggest how I can fix this?
I'm using a long HTML Template script in JS file, like:
var TEMPLATE = `
<div>
<ul>
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
</div>`;
It works in all browsers(including Chrome, Safari, Firefox & EDGE) but not in Internet Explorer 11, 10.
Can you suggest how I can fix this?
Share Improve this question edited Feb 25, 2019 at 12:39 Robbie JW 7391 gold badge9 silver badges22 bronze badges asked Oct 2, 2018 at 10:32 om_jaipurom_jaipur 2,1965 gold badges31 silver badges54 bronze badges 6- 4 Try using Babel: babeljs.io/docs/en – Michelangelo Commented Oct 2, 2018 at 10:34
- 4 It's because you're using template literals which aren't supported in IE, you can change it to a normal string or as @Michelangelo has said, use Babel – George Commented Oct 2, 2018 at 10:35
- Yes, I got it that "template literals aren't supported in IE". @Michelangelo, Can you describe how can I use Babel? I'm using AngularJS. – om_jaipur Commented Oct 2, 2018 at 10:51
- 1 Possible duplicate of Template literals not working in IE11 when "use strict" directive is used – Stuart Commented Oct 2, 2018 at 11:04
- 1 @om. No, this is not a programming class and I am not a teacher. The docs are clear. You have to figure this one out on your own. – Michelangelo Commented Oct 2, 2018 at 11:13
1 Answer
Reset to default 13If you don't need any of the advanced features available in template literals (such as ${foo}
), you might also consider using regular quotes and just escape the new lines to prevent syntax errors, like so:
var list = '\
<div>\
<ul>\
<li>first</li>\
<li>second</li>\
<li>third</li>\
</ul>\
</div>\
';
本文标签: javascriptES6Template strings hack for IE 11Stack Overflow
版权声明:本文标题:javascript - ES6 - Template strings hack for IE 11 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741226091a2361885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论