作者upo (其實我不多話...)
看板Web_Design
標題[問題] 為什麼document.write印出來的東西在另一頁?
時間Tue Oct 31 21:16:24 2006
小弟想寫一個簡易猜數字網頁
在印出幾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
1F:推 LPH66:因為document.write如果是在網頁載入完畢後才使用 10/31 22:29
2F:→ LPH66:會把網頁內容洗掉 10/31 22:29
3F:→ LPH66:你的要求似乎可以利用innerHTML達成 10/31 22:29
4F:→ upo:可以請問一下什麼是inner html嗎??? 11/01 07:32
5F:推 maxi326:innerhtml是某些dom物件所有的值,詳細上網找w3c+dom 11/02 14:02