Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement warning box, confirmation box and prompt box in JavaScript

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize warning box, confirmation box and prompt box in JavaScript". In daily operation, I believe many people have doubts about how to realize warning box, confirmation box and prompt box in JavaScript. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize warning box, confirmation box and prompt box in JavaScript". Next, please follow the editor to study!

JavaScript three pop-up boxes: warning box, confirmation box and prompt box

Warning box

If you want to ensure that the information is delivered to the user, you usually use an alert box.

When the warning box pops up, the user will need to click OK to continue.

Grammar

Window.alert ("sometext")

The window.alert () method can be written without the window prefix.

Example

Alert ("I am a warning box!")

Confirmation box

If you want the user to validate or accept something, you usually use the confirm box.

When the confirmation box pops up, the user will have to click OK or cancel to continue.

If the user clicks OK, the box returns true. If the user clicks cancel, the box returns false.

Grammar

Window.confirm ("sometext")

The window.confirm () method can be written without the window prefix.

Example

Var r = confirm ("Please press button")

If (r = = true) {

X = "you pressed confirm!"

} else {

X = "you pressed cancel!"

}

Prompt box

If you want the user to enter a value before entering the page, you usually use a prompt box.

When the prompt box pops up, the user will have to enter a value and click OK or cancel to continue.

If the user clicks OK, the box returns the input value. If the user clicks cancel, the box returns NULL.

Grammar

Window.prompt ("sometext", "defaultText")

The window.prompt () method can be written without the window prefix.

Example

Var person = prompt ("Please enter your name", "Bill Gates")

If (person! = null) {

Document.getElementById ("demo") [xss_clean] = "Hello" + person + "! how was your day?"

}

Break the line

To display line breaks in the pop-up box, add a character n after the backslash.

Example

Alert ("Hello\ nHow are you?")

At this point, the study on "how to realize the warning box, confirmation box and prompt box in JavaScript" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report