最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

在函數(shù)里添加document.write,為什么不像之前的例子在html后面追加輸出呢?

<!DOCTYPE HTML>

<html>

? ? <head>

? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

? ? ? ? <title>無標(biāo)題文檔</title>

? ? </head>

? ??

? ? <body>

? ? ? ? <form>

? ? ? ? ? 請(qǐng)選擇你愛好:<br>

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby1" value="music">? 音樂

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby2" value="music">? 登山

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby3" value="music">? 游泳

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby4" value="music">? 閱讀

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby5" value="music">? 打球

? ? ? ? ? <input type="checkbox" name="hobby" id="hobby6" value="music">? 跑步 <br>

? ? ? ? ? <input type="button" value = "全選" onclick = "checkall()">

? ? ? ? ? <input type="button" value = "全不選" onclick = "clearall();">

? ? ? ? ? <p>請(qǐng)輸入您要選擇愛好的序號(hào),序號(hào)為1-6:</p>

? ? ? ? ? <input id="wb" name="wb" type="text" >

? ? ? ? ? <input name="ok" type="button" value="確定" onclick = "checkone();">

? ? ? ? </form>

? ? ? ? <script type="text/javascript">

? ? ? ? function checkall(){

? ? ? ? ? ? var hobby = document.getElementsByTagName("input");

? ? ? ? ? ? for(i=0;i<hobby.length;i++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(hobby[i].type=="checkbox")

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? //document.write(hobby[i].value+"<br>");? ?//為什么這一行取消注釋,運(yùn)行的話,點(diǎn)擊全選過后,只有一個(gè)music的值輸出呢???

? ? ? ? ? ? ? ? ? ? hobby[i].checked=true;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? // 任務(wù)1? ? ??

? ? ? ? }

? ? ? ? function clearall(){

? ? ? ? ? ? var hobby = document.getElementsByName("hobby");

? ? ? ? ? ? ?for(i=0;i<hobby.length;i++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(hobby[i].type=="checkbox")

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? hobby[i].checked=false;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ?// 任務(wù)2? ? ??

? ? ? ? }

? ? ? ? function checkone(){

? ? ? ? ? ? var j=document.getElementById("wb").value;

? ? ? ? ? ? var j_id="hobby"+j;

? ? ? ? ? ? document.getElementById(j_id).checked=true;

? ? ? ? ?// 任務(wù)3

? ? ? ? }

? ? ? ? </script>

? ? </body>

</html>


正在回答

2 回答

我覺得頁面加載時(shí)先輸出html內(nèi)容

然后解析js代碼 如果有輸出流(document.write())那么就輸出確實(shí)能正常輸出

沒有的話解析完?

onload事件完成后再觸發(fā)別的事件(例如onClick)然后執(zhí)行該事件 里面有輸出流(document.write())的話就會(huì)覆蓋原界面吧

1 回復(fù) 有任何疑惑可以回復(fù)我~

document.write()一般用于頁面 onload 的時(shí)候。如果頁面已經(jīng) onload 完了,也就是頁面加載完成了,再調(diào)用docume.write()的話,那么,整個(gè) HTML 頁面將被覆蓋

轉(zhuǎn)自:https://www.cnblogs.com/holy-night/articles/5122860.html

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

在函數(shù)里添加document.write,為什么不像之前的例子在html后面追加輸出呢?

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)