HTML DOM open() ·½·¨

¶¨ÒåºÍÓ÷¨

open() ·½·¨¿É´ò¿ªÒ»¸öÐÂÎĵµ£¬²¢²Á³ýµ±Ç°ÎĵµµÄÄÚÈÝ¡£

Óï·¨

document.open(mimetype,replace)
²ÎÊý ÃèÊö
mimetype ¿ÉÑ¡¡£¹æ¶¨ÕýÔÚдµÄÎĵµµÄÀàÐÍ¡£Ä¬ÈÏÖµÊÇ "text/html"¡£
replace ¿ÉÑ¡¡£µ±´Ë²ÎÊýÉèÖú󣬿ÉÒýÆðÐÂÎĵµ´Ó¸¸Îĵµ¼Ì³ÐÀúÊ·ÌõÄ¿¡£

˵Ã÷

¸Ã·½·¨½«²Á³ýµ±Ç° HTML ÎĵµµÄÄÚÈÝ£¬¿ªÊ¼Ò»¸öеÄÎĵµ£¬ÐÂÎĵµÓà write() ·½·¨»ò writeln() ·½·¨±àд¡£

ÌáʾºÍ×¢ÊÍ

ÖØÒªÊÂÏµ÷Óà open() ·½·¨´ò¿ªÒ»¸öÐÂÎĵµ²¢ÇÒÓà write() ·½·¨ÉèÖÃÎĵµÄÚÈݺ󣬱ØÐë¼ÇסÓà close ·½·¨¹Ø±ÕÎĵµ£¬²¢ÆÈʹÆäÄÚÈÝÏÔʾ³öÀ´¡£

×¢ÊÍ£ºÊôÓÚ±»¸²¸ÇµÄÎĵµµÄÒ»²¿·ÖµÄ½Å±¾»òʼþ¾ä±ú²»Äܵ÷Óø÷½·¨£¬ÒòΪ½Å±¾»òʼþ¾ä±ú×ÔÉíÒ²»á±»¸²¸Ç¡£

ʵÀý

<html>
<head>
<script type="text/javascript">
function createNewDoc()
  {
  var newDoc=document.open("text/html","replace");
  var txt="<html><body>Learning about the DOM is FUN!</body></html>";
  newDoc.write(txt);
  newDoc.close();
  }
</script>
</head>
<body>

<input type="button" value="Write to a new document"
onclick="createNewDoc()">

</body>
</html>
VUE