2012-02-27 46 views
0

嘿傢伙我試圖創建一個窗口,當我點擊主文檔中的一個表列的特定數字,並對應於該列中的行打開在一個窗口打開不同的窗口。用於刪除主文檔中的行的腳本正在運行,但相同的腳本在打開的窗口中似乎不起作用。我不知道問題是什麼。請幫我出來。謝謝。JavaScript不工作在空白窗口

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>'); 
+0

什麼是在新窗口中的輸出增加基本的HTML標記,如<html><body>? – 2012-02-27 11:19:57

+0

在'document.write'中設置結尾'SCRIPT'標籤,如下所示:'<\/SCRIPT>',否則原始腳本將停止。 – Teemu 2012-02-27 11:22:36

回答

1

調試的最後一行:

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」中。這些在頁面解析過程中無法正常工作。

最後的最後一行添加到腳本:Window.document.close();

1

你似乎缺少一個啓動一個支架:

{if(confirm("Confirm to Delete??")document 

應該

{if(confirm("Confirm to Delete??"))document 

沒有檢查代碼的其餘部分,但如果它包含語法錯誤(這和其他可能),那麼顯然它不會運行。

0

您可能還需要之前<table>

+0

+''在哪裏放置評論過的樣式表。 – Teemu 2012-02-27 12:16:59