[課程概要]三個 javascript 的 function:alert(), prompt(), comfrim()

[使用方法]

<html>

<head>

<script>

要把函式打在這個裡面!

</script>

</head>

<body>

<script>

要把函式打在這個裡面!

</script>

</body>

</html>

[函式介紹]

【alert】

  1. 跳出一個視窗
  2. 只會顯示「確定」

1.PNG

2.PNG

 

【confirm】

  1. 跳出一個視窗
  2. 會出現「確定」和「取消」

comfrim("Want to go to Disneyland?");

3.PNG

(補充) 想要按OK時,直接連接到另外一個網站的方法

if ( comfrim("Want to go to Disneyland?") )

document.location.href = "https://www.hongkongdisneyland.com/zh-hk/";

 

【prompt】

  1. 會跳出一個視窗,讓user打字
  2. 可以拿來貯存user輸入的文字,作法如下

※ 一樣打在<script></script>裡面

var username;

username=prompt("What's your name?");

document.write("Hello" + username + "!");

 

4.PNG

arrow
arrow
    文章標籤
    javascript coursera
    全站熱搜
    創作者介紹
    創作者 atina 的頭像
    atina

    網頁設計的學習筆記

    atina 發表在 痞客邦 留言(0) 人氣()