我想要替換iframe,如果用戶再次通過選擇不同的輸入點擊getPrice按鈕。我已經編寫代碼並嘗試了幾件事情,但沒有任何結果。每次我不能使用document.body.appendchild()。我的代碼如下。請在這裏建議。想要替換基於Onlclick的iframe
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);
}
}
你有一個語法錯誤:'函數用getPrice()['應該是'函數用getPrice(){'' –
ifrm.setAttribute( 'SRC',「HTTP ://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName = Azure East');'我想你的代碼是這樣的? –
你想要替換完整的iframe或只是其內容? –