JavaScript - データ


■ページ目次

Top
■データの扱い
Top
■データ型
Top
■変数
■例題
  1. 変数を使うサンプル "HelloWorld02.html" です。
    1. <!-- HelloWorld02.html -->
    2. <html>
    3. <head>
    4. <title>わたしのホーム・ページ</title>
    5. <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS"/>
    6. </head>
    7. <body>
    8. <script type="text/javascript">
    9. <!--
    10. var message = "Hello World!"; // 文字列
    11. document.write(message);
    12. var number = 123456; // 数値
    13. document.write(number);
    14. var bool = true; // ブーリャン
    15. document.write(bool);
    16. var today = new Date(); // オブジェクト
    17. document.write(today);
    18. //-->
    19. </script>
    20. <noscript>JavaScriptが使用できません。</noscript>
    21. </body>
    22. </html>
Top
■実習
  1. 上記の変数を使うサンプル "HelloWorld02.html" は、改行されていません。改行タグも変数を使って、改行してください。("HelloWorld03.html" )
    1. <!-- HelloWorld03.html -->
    2. <html>
    3. <head>
    4. <title>わたしのホーム・ページ</title>
    5. <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS"/>
    6. </head>
    7. <body>
    8. <script type="text/javascript">
    9. <!--
    10. var br = "<br/>"; // 改行タグ
    11. // ここにコードを記述してください。
    12. //-->
    13. </script>
    14. <noscript>JavaScriptが使用できません。</noscript>
    15. </body>
    16. </html>
Top
■プロンプトからデータを受け取る
■例題
  1. プロンプトを使うサンプル "Prompt01.html" です。
    1. <!-- Prompt01.html -->
    2. <html>
    3. <head>
    4. <title>わたしのホーム・ページ</title>
    5. <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS"/>
    6. </head>
    7. <body>
    8. <script type="text/javascript">
    9. <!--
    10. var s = prompt("文字列を入力してください。", "");
    11. document.write(s);
    12. //-->
    13. </script>
    14. <noscript>JavaScriptが使用できません。</noscript>
    15. </body>
    16. </html>
Top
■実習
  1. プロンプトから整数値を入れるHTMLファイル "Prompt02.html" を作成してください。
    1. <!-- Prompt02.html -->
    2. <html>
    3. <head>
    4. <title>わたしのホーム・ページ</title>
    5. <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS"/>
    6. </head>
    7. <body>
    8. <script type="text/javascript">
    9. <!--
    10. // ここにコードを記述してください。
    11. document.write(n);
    12. //-->
    13. </script>
    14. <noscript>JavaScriptが使用できません。</noscript>
    15. </body>
    16. </html>
Top

inserted by FC2 system