警告ダイアログと型の変換


警告ダイアログ表示

  • JavaScriptで警告ダイアログを表示するには、「window.alert( )」を使う。



window.alert( )

  • [OK]ボタンのある警告ダイアログウィンドウに( )の中の文字列を表示する。
  • 「window.」は省略できる。



命令には引数を渡せる

  • 以下は同じ結果になる。

ソースコードJavaScript

<script>
  document.write( '<h1>はじめてのJavaScript<\/h1>' );
</script>

<script>
  document.write( '<h1>' ,  'はじめてのJavaScript' , '<\/h1>' );
</script>


ソースコード【 HTML 】

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>JavaScript初めての一歩</title>
</head>
<body>


<script>
  document.write('<h1>初めてのJavaScript<\/h1>');
</script>

<noscript>
  JavaScript対応ブラウザで表示してください。
</noscript>


</body>
</html>

ブラウザで表示