?????? ??
JavaScript? 4?? ???? ???? ??? ? ????.
window.alert()? ???? ?? ??? ?????.
HTML ??? ??? ??? document.write() ???? ?????.
innerHTML? ???? HTML ??? ???.
???? ??? ??? console.log()? ?????.
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! 這是一個(gè)按鈕"); } </script> </head> <body> <input type="button" onclick="myFunction()" value="Show alert box"> </body> </html>
document.write()
<!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>
innerHTML
<!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="點(diǎn)擊" /> </body> </html>
console.log()
????? ???? ???? ?? console.log() ???? ???? ????? JavaScript ?? ??? ? ????.
?????? F12? ???? ??? ??? ????? ??? ??? "??" ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> a = 5; b = 6; c = a + b; console.log(c); </script> </head> <body> <p>在瀏覽器中使用F12來(lái)調(diào)試,在調(diào)試窗口中點(diǎn)擊 "Console"</p> </body> </html>