【发布时间】:2016-11-23 10:02:06
【问题描述】:
如果用户通过选择不同的输入再次单击 getPrice 按钮,我想替换 iframe。我已经编写了代码并尝试了几件事,但没有任何结果。每次我不能使用 document.body.appendchild()。我的代码如下。请在这里建议。
function getPrice()[
var ifrm = document.createElement('iframe');
ifrm.id = "frameID";
ifrm.setAttribute('src', 'http://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName=Azure East
ifrm.setAttribute('align', 'right');
//ifrm.setAttribute('marginheight', '50');
ifrm.style.margin= "auto";
ifrm.scrolling="no";
ifrm.style.border= "0";
ifrm.style.margin= "0";
//document.body.insertBefore(ifrm, document.body.firstChild);
//alert();
if(document.getElementById("frameID")==null)
{
document.body.appendChild(ifrm);
}
else
{
alert("Else"); // I am getting control till here but what code to replace the existing iframe.
//var item = document.getElementById("frameID").childNodes[0];
item.replaceChild(ifrm,item.childNodes[0]);
alert("test");
document.body.appendChild(ifrm);
//ifrm.parentNode.replaceChild(ifrm, ifrm);
}
}
【问题讨论】:
-
你有一个语法错误:
function getPrice()[应该是function getPrice(){ -
ifrm.setAttribute('src', 'http://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName=Azure East');我猜你的代码是这样的? -
您要替换完整的 iframe 还是仅替换其内容?
-
"[" 在这里发布问题时只是拼写错误。我想替换 iframe。替换 iframe 和内容对我来说都是一样的,两者都对我有用
标签: javascript iframe