?????? ??
JavaScript??? ?? ??, ?? ??, ???? ??? ? ?? ??? ??? ??? ?? ? ????.
JavaScript ??()
??: ?? ??("sometext");
JavaScript?? ?? ??? ???? ??? ?? ??? ????:
<script type="text/javascript " >
Alert("?? ???? ??????!");
</script>
??? ?? ??? ?? ?? ?????. ?? ??? ???? ???? ?? ??? ???? ???. ??? ???? ?? ?? ??? ?????.
alert ???? ????? ????? ??? ???? HTML ??? ?? ??? ????? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function myFunction(){ alert("我是一個警告框!"); } </script> </head> <body> <input type="button" onclick="myFunction()" value="警告框" /> </body> </html>
JavaScript verify()
JavaScript?? ?? ??? ???? ??? ?? ??? ????.
??: ??confirm("sometext");
?? ??? ????? ???? ??? ?????.
?? ??? ???? ???? "??" ?? "??"? ???? ??? ??? ??? ? ????.
"??"? ???? ?? ??? true? ?????. "??"? ???? ?? ??? false? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script> if (confirm("您確認(rèn)要刪除該條信息嗎?")){ alert("您選擇了刪除!"); } else { alert("您選擇了不刪除"); } </script> </head> <body> </body> </html>
JavaScript ????()
??: prompt("sometext","defaultvalue");
?? ??
prompt()? ? ?? ????? ?????. ? ?? ????? ???????. ??? ???? ?? ? ?? ????? ?? ?? ?????. ?? ??? ?? ?? ??? ????()? ?? ??? ?(HTML ?? ??)? ????, ??? ??? null? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script> var name = prompt("請輸入您的名字:","默認(rèn)字符") if (name!=null && name!=""){ document.write("你好," + name + "!") } </script> </head> <body> </body> </html>
? ??
?? ???? ???? + "n"(n)? ???? ? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <button onclick="myFunction()">點擊顯示</button> <p id="demo"></p> <script> function myFunction(){ alert("Hello\nHow are you?"); } </script> </body> </html>