亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Output JavaScript

JavaScript boleh mengeluarkan data dalam 4 cara berbeza:

Gunakan window.alert() untuk muncul kotak amaran.

Gunakan kaedah document.write() untuk menulis kandungan ke dalam dokumen HTML.

Gunakan innerHTML untuk menulis pada elemen HTML.

Gunakan console.log() untuk menulis ke konsol penyemak imbas.


window.alert()

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
 <script src="/static/js/abc.js"></script><script>
    function myFunction()
    {
    window.alert("Hello! 這是一個按鈕");
    }
 </script>
</head>
<body>
  <input type="button" onclick="myFunction()" value="Show alert box">
</body>
</html>

document.write()

rreee

innerHTML

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
      <h1>Head</h1>
    <script>
        document.write('<p>hello document</p>');
    </script>
    <h2>Tail</h2>
</html>

console.log()

Jika penyemak imbas anda menyokong penyahpepijatan, anda boleh menggunakan kaedah console.log() Paparan nilai JavaScript dalam penyemak imbas.

Gunakan F12 dalam penyemak imbas untuk mendayakan mod nyahpepijat, dan klik menu "Konsol" dalam tetingkap penyahpepijatan.

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<script type="text/javascript">
    function getInnerHTML(){
    alert(document.getElementById("test").innerHTML);
    }
</script>
</head>
<body>
   <p id="test"><span color="#000">php中文網(wǎng)</span></p>
  <input type="button" onclick="getInnerHTML()" value="點擊" />
</body>
</html>


Meneruskan pembelajaran
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="/static/js/abc.js"></script><script> function myFunction() { window.alert("Hello! 這是一個按鈕"); } </script> </head> <body> <input type="button" onclick="myFunction()" value="Show alert box"> </body> </html>