?????? ??
JavaScript ?? ?
JavaScript??? ?? ??, ?? ??, ???? ??? ? ?? ??? ??? ??? ?? ? ????.
?? ??
?? ??? ???? ?? ??? ?? ? ??? ???? ? ?? ?????.
?? ??? ???? ???? ?? ??? ???? ??? ??? ? ????.
Syntax
window.alert("sometext");
window.alert() ???? window ?? ? Alert() ??? ?? ?? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function myFunction(){ alert("警告框!"); } </script> </head> <body> <input type="button" onclick="myFunction()" value="顯示警告框" /> </body> </html>
?? ??
?? ??? ????? ??? ??? ?????? ???? ? ?????.
?? ??? ???? ???? "??" ?? "??"? ???? ??? ??? ??? ? ????.
"??"? ???? ?? ??? true? ?????. "??"? ???? ?? ??? false? ?????.
Syntax
window.confirm("sometext");
window.confirm() ???? window ?? ?? ?? ??() ???? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>點擊按鈕,顯示確認框。</p> <button onclick="myFunction()">點我</button> <p id="demo"></p> <script> function myFunction(){ var x; var r=confirm("按下按鈕!"); if (r==true){ x="你按下了\"確定\"按鈕!"; } else{ x="你按下了\"取消\"按鈕!"; } document.getElementById("demo").innerHTML=x; } </script> </body> </html>
???? ??
???? ??? ???? ???? ?? ????? ?? ?? ????? ???? ???? ? ?? ?????.
???? ??? ???? ???? ?? ?? ??? ?? ?? ?? ?? ??? ???? ??? ??? ? ????.
???? ??? ???? ??? ?? ?????. ???? ??? ???? ?? ?? null???.
Syntax
window.prompt("sometext","defaultvalue");
window.prompt() ???? window ?? ? Prompt() ??? ?? ?? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>點擊按鈕查看輸入的對話框。</p> <button onclick="myFunction()">點我</button> <p id="demo"></p> <script> function myFunction(){ var x; var person=prompt("請輸入你的名字","Harry Potter"); if (person!=null && person!=""){ x="你好 " + person + "! 今天感覺如何?"; document.getElementById("demo").innerHTML=x; } } </script> </body> </html>
Line break
?? ???? ???? + "n"(n)? ???? ? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>點擊按鈕在彈窗總使用換行。</p> <button onclick="myFunction()">點我</button> <p id="demo"></p> <script> function myFunction(){ alert("Hello\nHow are you?"); } </script> </body> </html>