我有以下的javascript更換一個iframe的內容:Javascript to jQuery? (I幀)
// find existing iframe
var original = document.getElementsByTagName("iframe")[0];
// create new iframe
var newFrame = document.createElement("iframe");
newFrame.src = '/confirmation/show/' + this.value;
newFrame.className = 'field w45 right';
newFrame.id='confirmation_preview';
newFrame.title="Confirmation_Preview";
// find out where it goes
var parent = original.parentNode;
// replace the old with the new
parent.replaceChild(newFrame, original);
我做這種方式,因爲如果我只是改變了iframe src
,瀏覽器增加了一個進入歷史,所以如果用戶想要返回一個頁面,他們將不得不退回所有iframe重新加載。用這種方法,他們不會有這個問題。
我的問題是:我怎麼能在jQuery中實現相同的結果?
你爲什麼想要?它不可能更快。 – Blazemonger
您可以使用原生JavaScript和jQuery一起使用,爲什麼不保存此代碼?你是否在尋找像增加速度一樣的東西? –
' - >'http://api.jquery.com/replaceWith/ –