亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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

<!DOCTYPE HTML>

<html>

? ? <head>

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

? ? ? ? <title>無標題文檔</title>

? ? </head>

? ??

? ? <body>

? ? ? ? <form>

? ? ? ? ? 請選擇你愛好:<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>請輸入您要選擇愛好的序號,序號為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>");? ?//為什么這一行取消注釋,運行的話,點擊全選過后,只有一個music的值輸出呢???

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

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? // 任務1? ? ??

? ? ? ? }

? ? ? ? function clearall(){

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

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

? ? ? ? ? ? {

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

? ? ? ? ? ? ? ? {

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

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ?// 任務2? ? ??

? ? ? ? }

? ? ? ? function checkone(){

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

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

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

? ? ? ? ?// 任務3

? ? ? ? }

? ? ? ? </script>

? ? </body>

</html>


正在回答

2 回答

我覺得頁面加載時先輸出html內容

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

沒有的話解析完?

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

1 回復 有任何疑惑可以回復我~

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

轉自:https://www.cnblogs.com/holy-night/articles/5122860.html

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

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

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號