javascript - 将 HTML 写入新窗口打开的问题

标签 javascript html

我有这个代码:

 <div class="col3">
    <a id = "training-launch-button" href="javascript:void(0);" title=" My title here"  class="button" onClick="Test();">Launch</a>
 </div>     

  function Test() {
      var new_window= window.open('','Ratting','width=550,height=170,0,status=0,resizable=1');
      new_window.document.createElement("div");
      document.getElementsByTagName('div')[0].innerHTML = '<ol><li>html data</li></ol>';     

  }

有些不对劲,我没有看到有序列表项? 我最终想在新窗口中构建一些 HTML。

最佳答案

使用这个Js

function Test() {
   var newWindow= window.open('','Ratting','width=550,height=170,0,status=0,resizable=1');
   var newContent = "<HTML><HEAD><TITLE>One Sub Window</TITLE></HEAD>";
   newContent += "<BODY><div><ol><li>html data</li></ol></div>";
   newContent += "</BODY></HTML>";
   newWindow.document.write(newContent);
   newWindow.document.close();  
 }

关于javascript - 将 HTML 写入新窗口打开的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620972/

相关文章:

javascript - 使用 "getElementById"检索多个元素?

javascript - 悬停时将一个链接更改为两个

html - 测试自动化 html 元素选择器。元素 ID 或数据属性

javascript - 带phonegap的后退按钮(并查询手机?)

javascript - 如何创建一个在其值中带有引号的字符串变量?

javascript - 为什么在使用 .children 使 .modal 工作后还需要另一个 $()

html - 用于创建数学方程式的编辑器

javascript - 如何在完成某些任务后下载文件

java - 我如何使用 html 在 JTextPane 中使用 tabulator\whitespace?

javascript - 控制台响应 json