函數里的document.write()為什么會清除掉當前網頁內容?如果現在當前網頁內容下順序輸出要怎么做?
如題。實驗代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>confirm</title>
? <script type="text/javascript">
? document.write("hello");
? function rec(){
? ? var mymessage=confirm("你是女士嗎?") ? ? ? ? ;
? ? if(mymessage==true)
? ? {
? ? document.write("你是女士!");
? ? }
? ? else
? ? {
? ? ? ? document.write("你是男士!");?
? ? }
? </script>
</head>
<body>
? ? <h1>練習,這段話在點擊按鈕后會消失</h1>
? ? <input name="button" type="button" onClick="rec()" value="點擊我,彈出確認對話框" />
</body>
</html>
2018-07-30
我剛才看錯了,你的方法沒有大括號。你加個大括號,就好了,沒有什么問題的,記住,程序是從上到下執行的就行了,除了調用方法的特殊情況
2018-07-30
document.write();是將write()的內容輸出,程序的執行是順序結構,所以會輸出出來。該程序不會輸出hell