仅在 IE11 中出现严格模式错误。我可以只为这个浏览器取消严格模式吗?

Strict mode error only in IE11. Can I take off strict mode just for this browser?

我在这行代码中收到错误`严格模式下不允许分配只读属性'

wrapper.style = 'transition: transform 3s;';

这是它所在函数的一部分:

'use strict';
function work() {
  var wrapper = document.getElementById( 'wrp' ),
  infoPage = document.getElementById( 'i-pg' ),
  body = document.getElementById( 'body' ),

  carA = document.getElementById( 'car-a' ),
  keyA = document.getElementById( 'key-a' ),
  manualA = document.getElementById( 'manual-a' ),
  wheelA = document.getElementById( 'wheel-a' );

  if( this.id === 'info' ) {
    wrapper.style = 'transition: transform 3s;'; //PROBLEM LINE
    wrapper.classList.add( 'up' );
    body.classList.add( 'dark' );
    infoPage.classList.remove( 'down' );
  }
}

此代码在我测试过的所有现代浏览器中都能完美运行。只有在 IE11 中,这会破坏整个站点,停止 运行 的所有后续行。

如果我取出第一行:'use strict'; 一切正常。 在保持严格模式的同时有一个简单的修复方法吗?或者只针对 IE11 并以某种方式删除该浏览器的严格模式?

可能有更好的方法。

为什么不修复它,而不是忽略错误?

wrapper.style.transition = 'transform 3s;';

我认为您可能会遇到错误,因为您试图将 transform 3s 分配给样式 属性,而实际上您应该将其分配给过渡 属性。 像这样:wrapper.style.transition = 'transform 3s';

结帐:

https://devtidbits.com/2016/06/12/assignment-to-read-only-properties-is-not-allowed-in-strict-mode/#comment-1611

显然你应该像这样使用它

myEle.style.cssText = "color: red;" // or
myEle.setAttribute("class", "myClass"); // Multiple style properties
//For newly created style sheet objects, you must first append the element to the document before you can set cssText.

然而,即使在应用该修复程序后,我仍然遇到相同的错误...