我已經添加下面的Java腳本代碼來創建一個彈出窗口:的JavaScript彈出窗口替換原有的HTML源代碼
document.write('<center>');
document.write('<div id="productComapreBox" style="border:0px solid #0066FF ; padding:5px; font-size:150%; text-align:center; display:none; width:820px; height:600px;">');
document.write('<input type="image" src="images/close.png" width="30" height="30" alt="X" onClick="'+eval(Popup.hide("productComapreBox"))+'" style="cursor:pointer; float:right; z-index:20;">');
document.write('<div style="z-index:20;">');
document.write('<iframe width="800px" height="600px" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0" style="background-color:#FFFFFF;" src="<?php echo $domainName; ?>productComaprePop.php?productComapreIds='+productId+'"></iframe>');
document.write('</div>');
document.write('</div>');
document.write('</center>');
它打開彈出窗口,我想,但它替代原有的HTML源。如何防止這一點。
請幫
感謝
您可能想了解一下'appenChild()'方法。請注意,應儘可能避免使用JavaScript生成HTML,與內聯樣式完全相同,並且僅當您無法執行其他操作時才應使用iFrame。 –
你在哪裏可以找到這個'document.write()'函數?創建內容到現有頁面時不應使用它,而是用於創建全新文檔。 – Teemu
'document.write'將取代內容。不要使用它。改爲使用動態DOM操作。 [HTMLElement.appendChild](https://developer.mozilla.org/en-US/docs/Web/API/Node.appendChild) – marekful