JavaScript兩個(gè)常用的客戶端輸出方法
常用的兩個(gè)客戶端輸出方法
document.write(str)
描述:在網(wǎng)頁(yè)的<body>標(biāo)記,輸出str的內(nèi)容。
document意思“文檔”,就是整個(gè)網(wǎng)頁(yè)了。
document是一個(gè)文檔對(duì)象,代表整個(gè)網(wǎng)頁(yè)。
?write()是document對(duì)象的一個(gè)輸出方法。
“.”小數(shù)點(diǎn):通過小數(shù)點(diǎn)(.)來調(diào)用對(duì)象的方法。
str:表示要輸出的內(nèi)容。
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //在<body>中輸出一句話 document.write("歡迎來到php.cn"); </script> </head> <body> </body> </html>
window.alert(str)
描述:在當(dāng)前窗口中彈出一個(gè)警告對(duì)話框,str為對(duì)話框中顯示的內(nèi)容。
window代表當(dāng)前瀏覽器窗口,window是一個(gè)窗口對(duì)象。
alert()方法:彈出一個(gè)對(duì)話框。
str:表示要輸出的內(nèi)容。
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //打開網(wǎng)頁(yè)時(shí),彈出一個(gè)對(duì)話框 window.alert("歡迎來到php.cn"); </script> </head> <body> </body> </html>