错误“0:'Open' 未定义”和 "SCRIPT1005: SCRIPT1005: Expected '('" 如何修复这些错误?

Errors "0: 'Open' is not defined" and "SCRIPT1005: SCRIPT1005: Expected '('" How do I fix these errors?

仅在 Microsoft edge 中出现单击问题。

function closepage(){
 var Modal = document.getElementById('Modal');
 var Modalparent = null;
 try{ Modalparent = ((Modal.parentElement) ? Modal.parentElement : ((Modal.parentNode) ? Modal.parentNode : null));}catch{return;}
 if(Modalparent == null)return;
 Modalparent.removeChild(Modal);
 document.getElementsByTagName('body')[0].className = "";
}

您需要在 Edge 中像这样指定 catch 参数:

try{
  ...
} catch(error){
  ...
}

try{...}catch{...} 没有参数被 Edge 称为 Optional catch binding which is not supported

因此可以运行的代码示例如下所示:

function closepage() {
  var Modal = document.getElementById('Modal');
  var Modalparent = null;
  try {
    Modalparent = ((Modal.parentElement) ? Modal.parentElement : ((Modal.parentNode) ? Modal.parentNode : null));
  } catch (error) {
    return;
  }
  if (Modalparent == null) return;
  Modalparent.removeChild(Modal);
  document.getElementsByTagName('body')[0].className = "";
}
<div id="Modal">Modal</div>
<button onclick="closepage()" type="button">test</button>