Internet explorer 我试着只使用document.write()(输出)

Internet explorer 我试着只使用document.write()(输出),internet-explorer,document.write,Internet Explorer,Document.write,我尝试使用下面的代码使用document.write输出计算结果,但IE仅给出结果。其他浏览器只是将表单返回给我。我不知道为什么? 你不应该这样写。完成整个文档树后,document.write将覆盖整个页面。在呈现页面时,它实际上只能在内联脚本片段中使用 即使这样,也不推荐这样做。使用jQuery,或者对于真正令人沮丧的体验,使用document.createElement。。和appendChilddocument.createTextNode <html> <head&

我尝试使用下面的代码使用document.write输出计算结果,但IE仅给出结果。其他浏览器只是将表单返回给我。我不知道为什么?

你不应该这样写。完成整个文档树后,document.write将覆盖整个页面。在呈现页面时,它实际上只能在内联脚本片段中使用

即使这样,也不推荐这样做。使用jQuery,或者对于真正令人沮丧的体验,使用document.createElement。。和appendChilddocument.createTextNode

<html>
<head>
<script type="text/javascript">
function main()
{
    var area=form1.height.value*form1.base.value/2;
    this.document.write("<p>The area is "+area+"</p>");
    //return form1.area.value=area;
}
</script>
</head>
<body>
<h2>Triangle Area</h2>
<form method="get" name="form1" id="form1">
  <p>Height:
    <input name="height" type="text">
   </p>
  <p>Base: 
    <input name="base" type="text"> 
   </p>
  <p>
    <input type="submit" name="Submit" value="Calculate" onclick="main()">
  </p>
</form>

</body>
</html>