How do I pop up an alert in Javascript?

前端 未结 9 848
半阙折子戏
半阙折子戏 2021-01-19 16:03

How do I pop up an alert in Javascript?

I tried alert\"HELLO\" but that didn\'t work.

Can someone tell me the correct syntax?

Oh by the

相关标签:
9条回答
  • 2021-01-19 16:43

    if you're having problems with alerts, it probably means your javascript is disabled in your browser, but if it isn't these methods should solve your issue.

    <script type="text/javascript" >
        window.alert("Hello World!");
    
        alert("Hello World!");
    </script>
    
    0 讨论(0)
  • 2021-01-19 16:43
    <script type="text/javascript">alert("Hello");</script>
    
    0 讨论(0)
  • 2021-01-19 16:43
    <html>
    <head>
    <script type="text/javascript">
      function myFunction(){
        alert("hello");
      }
    </script>
     </head>
    <body>
    <input type="submit" onClick="myFunction()">
    </body>
    </html>
    

    Here is the JavaScript function which has an alert box. This function is called by clicking on the submit button.

    0 讨论(0)
  • 2021-01-19 16:50

    Unlike VBScript, Javascript requires parentheses around function calls.

    Therefore, you need to write alert("Hello!");

    It's also prefereable (but not required) to end every statement with a semicolon ;.

    Finally, if you aren't already, you need to put it in a script block, like this:

    <script type="text/javascript">
        alert("Hello!");
    </script>
    

    In responce to the end of your original question, there is no "javascript exe". You can put javascript inside a script tag in an HTML page, or you can make a standalone .js file and double-click on it (in Windows) to run it using WSH.

    0 讨论(0)
  • 2021-01-19 16:53

    There are a few ways.

    1. Use your web browser, type this code in address bar.

      javascript:alert("Hello World!")

    2. Open web developer in your web browser, go to console and type:

      alert("Hello World!")

    3. Type the code in .html or .js code as shown in other answers above.

    0 讨论(0)
  • 2021-01-19 16:54

    You need to add parentheses:

    alert("HELLO");
    
    0 讨论(0)
提交回复
热议问题