亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript popup

You can create three kinds of message boxes in JavaScript: warning box, confirmation box, and prompt box.

JavaScript alert()

Syntax: alert("sometext");

at Use the alert command in JavaScript to create a message warning box:

<script type="text/javascript">
alert("I am the prompt text!");
< ;/script>

The message warning box is in dialog mode. When the warning box appears, the user needs to click the OK button to close the warning box before continuing the operation. The

alert command has one parameter, which is the text string you want to display to the user, which is not in HTML format.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function myFunction(){
   alert("我是一個警告框!");
}
</script>
</head>
<body>
   <input type="button" onclick="myFunction()" value="警告框" />
</body>
</html>

JavaScript confirm()

Use the confirm command in JavaScript to create a message confirmation box:

Syntax:confirm("sometext");

The confirmation box is usually used to verify whether the user operation is accepted.

When the confirmation card pops up, the user can click "Confirm" or "Cancel" to confirm the user operation.

When you click "Confirm", the confirmation box returns true. If you click "Cancel", the confirmation box returns false.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
<script>
    if (confirm("您確認要刪除該條信息嗎?")){
    alert("您選擇了刪除!");
    } else {
    alert("您選擇了不刪除");
    }
</script>
</head>
<body>
</body>
</html>

JavaScript prompt()

Syntax: prompt("sometext","defaultvalue");


Syntax description

prompt() allows two parameters: the first parameter is the prompt text to be displayed, and the second parameter is the default input character. If the input box is not empty, prompt() returns the value of the input box (HTML format is supported), otherwise it returns null.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
<script>
    var name = prompt("請輸入您的名字:","默認字符")
    if (name!=null && name!=""){
    document.write("你好," + name + "!")
    }
</script>
</head>
<body>
</body>
</html>

Line break

The pop-up window uses backslash + "n"(\n) to set line break.

<!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>


Continuing Learning
||
<!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("我是當前顯示文字\n我是換行文字"); } </script> </body> </html>
submitReset Code