HTML ??
JavaScript? HTML ???? ?? ???? ????? ????.
HTML <script> ??
<script> ??? JavaScript? ?? ?????? ????? ???? ? ?????. .
<script> ??? ???? ?? ????? src ??? ?? ?? ???? ??? ??? ? ????.
JavaScript? ??? ??, ?? ??? ?? ? ?? ??? ????? ?? ????? ?????.
?
?? ????? "How are you?"? ????? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <script> document.write("你好嗎?") </script> </body> </html>
???? ?? ?? :
? ?????
Javascript ????? ?? ??? ?????
HTML<noscript>
<noscript> ??? ?????? ????? ?????? ??? ????? ????? ? ????? ???? ?? ??? ?? ????? ??? ? ?? ?? ?? ???? ?????.
<noscript> ???? ?? HTML ???? body ??? ?? ?? ??? ??? ? ????.
<noscript> ??? ???? ????? ????? ???? ??? ????? ????? ???? ?????.
????
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <script> document.write("Hello World!") </script> <noscript>抱歉,你的瀏覽器不支持 JavaScript!</noscript> <p>不支持 JavaScript 的瀏覽器會使用 <noscript> 元素中定義的內(nèi)容(文本)來替代。</p> </body> </html>
???? ?? ??:
JavaScript ??( ? ???? JavaScript ??????)
JavaScript ?? ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p> JavaScript 能夠直接寫入 HTML 輸出流中: </p> <script> document.write("<h1>這是一個標(biāo)題</h1>"); document.write("<p>這是一個段落。</p>"); </script> <p> 您只能在 HTML 輸出流中使用 <strong>document.write</strong>。 如果您在文檔已加載后使用它(比如在函數(shù)中),會覆蓋整個文檔。 </p> </body> </html>
???? ?? ??:
JavaScript ??? ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <h1>我的第一個 JavaScript </h1> <p id="demo"> JavaScript 可以觸發(fā)事件,就像按鈕點擊。</p> <script> function myFunction() { document.getElementById("demo").innerHTML="Hello JavaScript!"; } </script> <button type="button" onclick="myFunction()">點我</button> </body> </html>
????? ???? ??
JavaScript ?? HTML ???:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <h1>我的第一段 JavaScript</h1> <p id="demo"> JavaScript 能改變 HTML 元素的樣式。 </p> <script> function myFunction() { x=document.getElementById("demo") // 找到元素 x.style.color="#ff0000"; // 改變樣式 } </script> <button type="button" onclick="myFunction()">點擊這里</button> </body> </html>