document.getElementById("myFrame").setAttribute("src") = "http://www.yahoo.com/";
myFrame是一個iframe元素...當進入這個開發人員控制檯,它給了我錯誤「賦值中無效的左側」我試圖更新iframe。有沒有我忘記的方法?簡單的javascript問題
document.getElementById("myFrame").setAttribute("src") = "http://www.yahoo.com/";
myFrame是一個iframe元素...當進入這個開發人員控制檯,它給了我錯誤「賦值中無效的左側」我試圖更新iframe。有沒有我忘記的方法?簡單的javascript問題
在這裏,我固定它
document.getElementById("myFrame").setAttribute("src", "http://www.yahoo.com/");
setAttribute
有兩個參數:
document.getElementById("myFrame").setAttribute("src", "http://www.yahoo.com/");
您正試圖將DOM對象設置爲字符串"http://www.yahoo.com/"
...這是無效的。
您不能分配的函數調用的東西,試試這個來代替:
document.getElementById("myFrame").setAttribute("src", http://www.yahoo.com/");
嘗試......
document.getElementById("myFrame").setAttribute("src","http://www.yahoo.com/");
修復了您的拼寫錯誤。 – lonesomeday 2011-01-10 22:29:18
設置src
屬性時,您並不需要setAttribute
:
document.getElementById('myFrame').src = 'http://www.yahoo.com/';
請參閱https://developer.mozilla.org/en/DOM/element.setAttribute – 2011-01-10 22:28:01