-1
我有一個帶有多個按鈕的頁面,每個按鈕都與打開新窗口的加載函數綁定,然後將其設置爲在頁面加載後單擊哪個按鈕。 我一直在對象中存儲選項,正在使用的選項在currentTile
之下。但是,一旦加載頁面,出現的文字就是undefined
,但是我沒有在load()
中定義currentTile
?爲什麼屬性在函數中定義時未定義?
function tile(question, answer, points) {
this.question = question;
this.answer = answer;
this.points = points;
}
var currentTile = {};
var testTile = new tile("How are you?", "Fine", 200);
function load(tile) {
currentTile = tile;
window.open("question.html", "_self");
}
function setText() {
document.getElementById("qSlot").innerHTML = currentTile.question;
document.getElementById("value").innerHTML = "" + currentTile.points + "";
}
load()
被稱爲像這樣的HTML:提前 <td onclick="load(testTile)"></td>
感謝。
你在哪裏調用加載函數? – Geeky
您正在將傳遞給'load'('tile')的值分配給'currentTile',但您並未顯示如何調用'load'。可推測你沒有傳遞任何價值的功能。 –
我在html代碼中調用它,''td onclick =「load(testTile)」>' –