JavaScript 无法在空白窗口中运行

标签 javascript window

嘿,大家好,我正在尝试创建一个窗口,当我单击主文档中表格列的特定数字时,该窗口会打开,并且对应于该列中的行会在不同的窗口中打开。用于删除主文档中的行的脚本正在运行,但相同的脚本似乎在打开的窗口中不起作用。我不知道问题是什么。请帮我解决一下。谢谢。

 Window = window.open('','W1','width=700,height=500');
//Window.document.write("<style type='text/css'>table,th,tr{ cellspacing=0;border-    collapse:collapse;border-radius:5px;-moz-border-radius:5px;}</style>");

Window.document.write('<table id="T1" border="1" ><th width="60">S,no.</th><th  width="110">Name</th><th width="110">Op Name</th><th width="110">ID</th><th width="110">Synonym record numbers</th><th width="60">Total Duplicity weight</th><th></th></table>');
 Window.document.write("<button type=\"button\" value=\"delal\" id=\"delal\" name=\"delal\" onclick=\"delall()\">Delete checked</button>");
 Window.document.getElementById("T1").style.borderCollapse="collapse";
 Window.document.getElementById("T1").style.padding="5";
 Window.document.getElementById("T1").style.backgroundColor="#E0C77A";
 Window.document.getElementById('T1').innerHTML += F+M;
Window.document.write('<script type="text/javascript">function deleteRow1(i)  {if(confirm("Confirm to Delete??")document.getElementById("T1").deleteRow(i);}function delall(){if(confirm("Are you sure you want to delete the selected rows?")){crows=document.getElementsByName("delcheck");for (i = 0; i<crows.length;i++){if(crows[i].checked){document.getElementById("T1").deleteRow(crows[i].parentNode.parentNode.rowIndex);i--;}}}</script>');

最佳答案

调试最后一行:

Window.document.write('<script type="text/javascript">function deleteRow1(i)  {if(confirm("Confirm to Delete??"))document.getElementById("T1").deleteRow(i);}function delall(){if(confirm("Are you sure you want to delete the selected rows?")){crows=document.getElementsByName("delcheck");for (i = 0; i<crows.length;i++){if(crows[i].checked){document.getElementById("T1").deleteRow(crows[i].parentNode.parentNode.rowIndex);i--;}}}}<\/script>');

另请注意 JamieJag 的回答,以及我对该答案的评论。这意味着,您必须通过脚本构建整个 HTML 页面,并使用结束标签。当您拥有样式表时,您还可以删除所有内部样式设置,并将 ìnnerHTML 放入 document.write 中。这些在页面解析期间无论如何都不会起作用。

最后将最后一行添加到脚本中:Window.document.close();

关于JavaScript 无法在空白窗口中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9464062/

相关文章:

javascript - 是否有可能在 Javascript 或 Python 中在 R 中实现类似 "non standard evaluation"的东西?

linux - 窗口是否需要图形环境才能存在?

javascript - JavaScript:window.top和top.window有什么区别

macos - 获取碳前窗的标题

javascript - 在单击之前禁用 iframe 上的滚动?

javascript - React.js map() 不是一个函数?

java - 清除 NetBeans 中的输出窗口

window - 如何在 Python 3k 中获取窗口或全屏截图? (不含 PIL)

javascript:用于打开和关闭定时颜色更改的按钮

javascript - 哪些 CSS 按钮在 Web View (iPhone/android)中工作得很好?