看板 Ajax 關於我們 聯絡資訊
這是scope解析問題。 setTimeout, setInterval是window物件底下的函數,你在裡面用到this 這個this會指到window而不是你想的地方。 你可以先把this傳給一個區域變數,然後在setTimeout或setInterval中用這個變數 例如: addtext=function(){ this.add=function(){ document.getElementById('test').value+='a'; var thisref = this; setTimeout(thisref.add(),1000); } } -- Sapere Aude! 這就是啟蒙運動的口號! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.250.95.16
awpadam:謝謝您的回應,又學到了。 03/06 18:04