javascript弹出窗口替换原始html源代码
我添加了以下java脚本代码来创建弹出窗口:javascript弹出窗口替换原始html源代码,javascript,Javascript,我添加了以下java脚本代码来创建弹出窗口: 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;">'); do
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>');
document.write(“”);
文件。写(“”);
文件。写(“”);
文件。写(“”);
document.write('可以使用以下代码,而不是使用document.write-
HTML-
您必须附加新元素,而不是覆盖当前的元素
例如
您可能想了解appenChild()
方法。请注意,应尽可能避免从javascript生成HTML,就像内联样式一样,并且只有在无法执行其他操作时才应使用iFrame。您在哪里找到此文档。write()
函数?在为现有页面创建内容时不应该使用它,而是为了创建全新的文档。document.write
将替换内容。不要使用它。改用动态DOM操作。我看不到任何创建弹出窗口的代码。这也是一种非常过时的JS/HTML样式。。。问题是iframe url是动态的,取决于选择用于比较的产品。请参见src=“productcomapreop.php?productComapreIds=”+productId+”您可以将完整url的值分配给php中的一个变量,如下-$fullurl=$domainName.'productcomapreop.php?productComapreIds='.+productId+;
。然后只需使用此-src=“”
我在回答中也更新了这一点。但问题是,在php中,完整url中的productId在什么时候不知道。只有在用户选中用于比较产品的复选框时,我才能通过javascript获得它。也就是说,在我的代码中,可以有javascript“+productId+”“我已经根据您的要求更新了我的答案。我希望它能帮助Hanks buddy。完成了。一个小的更正而不是document.getElementById('frame')。scr=fullurl;它将是'src'。
<div id="container" style="display: none;">
<center>
<div id="productComapreBox" style="border:0px solid #0066FF ; padding:5px; font-size:150%; text-align:center; display:none; width:820px; height:600px;">
<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;">
<div style="z-index:20;">
<iframe id="frame" width="800px" height="600px" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0" style="background-color:#FFFFFF;></iframe>
</div>
</div>
</center>
</div>
function unhide(){
var fullurl = "<?php echo $domainName; ?>productComaprePop.php?productComapreIds='" + productId + "'";
document.getElementById('frame').scr=fullurl;
document.getElementById('container').style.display="block";
}
var location = document.getElementById('#somElement');
var fragment = document.createDocumentFragment();
var div = document.createElement('DIV');
var secondDiv = document.createElement('DIV');
div.appendChild(secondDiv);
fragment.appendChild(div);
location.appendChild(fragment);