Python-Ref > Mimo python > JavaScript > Hello JavaScript
 
 

^^->
Klíčová slova
Moduly
Knihovní funkce

Hello JavaScript

JavaScript allows the content of a page to be dynamically changed on the clients side as well as to respond to user-generated actions. The following simple examples show some simple pages with JavaScript.
Expand/Shrink
Zdroj: (js1-1.html)
  1   <html xmlns="http://www.w3.org/1999/xhtml">
  2   <head>
  3    <title>Javascript example</title>
  4    <meta content="text/html; charset=utf-8" http-equiv="content-Type"/>
  5   </head>
  6   <body>
  7     <button onclick="alert('Hello world');">Hello</button>
  8   </body>
  9   </html>
Doba běhu: 2.2 ms
Javascript code may be placed inside HTML:
Expand/Shrink
Zdroj: (js1-2.html)
  1   <html xmlns="http://www.w3.org/1999/xhtml">
  2   <head>
  3    <title>Javascript example</title>
  4    <meta content="text/html; charset=utf-8" http-equiv="content-Type"/>
  5    <script type="text/javascript">
  6      function hello_world() {
  7        alert("Hello world!");
  8   }
  9    </script>
 10   </head>
 11   <body>
 12     <button onclick="javascript:hello_world();">Hello</button>
 13   </body>
 14   </html>
Doba běhu: 2.2 ms
.. or in an external file:
Expand/Shrink
function hello_world() {
    alert("Hello world!");
}
Zdroj: (js1-3.html)
  1   <html xmlns="http://www.w3.org/1999/xhtml">
  2   <head>
  3    <title>Javascript example</title>
  4    <meta content="text/html; charset=utf-8" http-equiv="content-Type"/>
  5    <script src="infiles/js1-3.js" type="text/javascript"> </script>
  6   </head>
  7   <body>
  8     <button onclick="javascript:hello_world();">Hello</button>
  9   </body>
 10   </html>
Doba běhu: 2.3 ms