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