[問題] 為什麼document.write印出來的東西在另一頁?

看板Web_Design作者 (其實我不多話...)時間19年前 (2006/10/31 21:15), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/1
小弟想寫一個簡易猜數字網頁 在印出幾A幾B的時候 居然會跳到一個新的網頁~ 不知道這是為什麼呢?? 片段程式碼如下 function tip() { acount=0; bcount=0; if(flag==0){ answer = new Array(); answer[0]=2; answer[1]=5; answer[2]=3; answer[3]=8; } else{ question(); flag=0; } tr = new Array(); tr[0]=document.jayc.a.value; tr[1]=document.jayc.b.value; tr[2]=document.jayc.c.value; tr[3]=document.jayc.d.value; if(tr[0]==answer[0] && tr[1]==answer[1] && tr[2]==answer[2] && tr[3]==answer[3]){ alert("答對囉!"); return; } for(i=0;i<4;i++){ if(tr[i]==answer[i]){ acount++; } } for(i=0;i<4;i++){ for(j=0;j<4;j++){ if(tr[i]==answer[j]){ bcount++; } } } bcount=bcount-acount; document.write(""+acount+" A "+bcount+"B"); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.223.147

10/31 22:29, , 1F
因為document.write如果是在網頁載入完畢後才使用
10/31 22:29, 1F

10/31 22:29, , 2F
會把網頁內容洗掉
10/31 22:29, 2F

10/31 22:29, , 3F
你的要求似乎可以利用innerHTML達成
10/31 22:29, 3F

11/01 07:32, , 4F
可以請問一下什麼是inner html嗎???
11/01 07:32, 4F

11/02 14:02, , 5F
innerhtml是某些dom物件所有的值,詳細上網找w3c+dom
11/02 14:02, 5F
文章代碼(AID): #15HqnVWF (Web_Design)