js in three dialog

When user interactive window, the three most common method is to alert (), confirm () and prompt (), that is, three kinds of pop manner.

alert()、confirm()、prompt()

First, the alert box: alert () 

Alert box, only one button "OK" no return value, you need to click the OK button in order to proceed

 

 Code:

< HTML > 
< head > 
    < title > HTML page </ title > 
    < Script Language = "JavaScript" > 
        Alert ( " warning " ); // bomb "Warning" at page 
    </ Script > 
</ head > 
</ HTML >

 

Additional: removal of the head of the website information alert box 

Code (recommended the establishment of a global js file for easy reference, the code needs to be placed in front, otherwise failure)

<!--<editor-fold desc="去除 消息框头的 网站信息">-->
<script language="javascript">
    window.alert = function (name) {
        var iframe = document.createElement("IFRAME");
        iframe.style.display = "none";
        iframe.setAttribute("src", 'data:text/plain,');
        document.documentElement.appendChild(iframe);
        window.frames[0].window.alert(name);
        iframe.parentNode.removeChild(iframe);
    };
</script>
<!--</editor-fold>-->

 

 

 =======================================================================================================

Second, the confirmation box: confirm () 

 Confirmation box, there are two buttons, OK and Cancel (off), the user clicks, returns true or false. When the user clicks, in order to proceed.

 

 

 Code:

< HTML > 
< head > 
    < title > HTML page </ title > 
    < Script Language = "JavaScript" > 
        var RES; 
        RES = Confirm The ( " confirm or cancel? " ); // pop-up dialog box on page 
        IF (RES = = to true ) 
            Alert ( " you point to confirm! " );
         the else 
            Alert ( " you point to cancel " );
     </ Script >
</head>
</html>

 

 

======================================================================================================

Third, the prompt box: prompt ()

Prompt box, there are two buttons and input boxes, you can return a message entered by the user.

When the prompt box appears, users need to enter a value, then click OK or Cancel button to continue.

If the user clicks to confirm, then return the value entered by the user.

If the user clicks Cancel, the returned value is null.

Code

< HTML > 
< head > 
    < title > HTML page </ title > 
</ head > 
< body > 
< the INPUT of the type = "the Button" value = "new window opens website" onclick = "A ()"  /> 
< Script Language = "JavaScript" > 
    function A () {
         var name; 
        name = prompt ( " enter your name " , "" );// message box pops up on the page, the result of user input to the variable name
        IF (name == null || name == "" ) { 
            Alert ( " You chose to cancel [No] button! " ); 
            A () 
        } the else { 
            Alert ( " you choose the [OK OK] button. " ) ; 
        } 
    } 
</ Script > 
</ body > 
</ HTML >

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/caitangbutian/p/11546504.html