JavaScript 四種顯示數據方式
阿新 • • 發佈:2018-10-19
rip ack ctype document doc set utf-8 看不見 輸出
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript 顯示數據</title> <style type="text/css"> p{ background-color: yellow; } </style> <script> window.onload=function () {// 方式1:使用window.alert()彈出警告框 alert(‘hello,My name is Apollo !‘); // 方式2:使用document.write()方法將內容寫到HTML文檔中 // document.write(‘hello,My name is Apollo !‘); // 方式3:使用innerHtml方法寫入到Html元素中去 // 1.JS入口函數有一個覆蓋現象,假如你不註釋上面document.write()相關代碼,下面代碼是看不見的. //2.使用getElementsByTagName必修要加上索引,因為p標簽很多,你這樣得到的是一個數組 // document.getElementsByTagName(‘p‘)(0).innerHTML=‘hello,My name is Apollo !!!‘; // 方式4使用console.log()控制臺輸出 console.log(‘hello,My name is Apollo !‘); } </script> </head> <body> <div> <p>這裏的代碼將會被替換......</p> <p>這裏是第二個p標簽</p> </div> </body> </html>
JavaScript 四種顯示數據方式