オブジェクトとプロパティ

window.document.write()→文字列を書きだす。

  • ( )の中の文字列を表示します。「window.」は省略できます。


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Hello!</title>
</head>
<body>
<script type="text/javascript">
<!--
  window.document.write('Hellow World!!');
//-->
</script>
<noscript>
<!--
 代替えメニューを表示するHTMLのコード
-->
</noscript>
</body>
</html>




<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
</head>
<body>
<script type="text/javascript">
<!--
  document.write('<h1>Hello JavaScript!<\/h1>');
//-->
</script>
</body>
</html>


背景色・文字色

  • document.fgColor→文字色
  • document.bgColor→背景色


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>プロパティ</title>
</head>
<body onLoad = ' window.defaultStatus = "色の設定" ' >
<script type="text/javascript">
<!--
  document.fgColor = '#FF0000';
  document.bgColor = '#EEEEEE';
//-->
</script>
<p>文字色と背景色を変更しました。</p>

<noscript>
<!--
  代替えメニューを表示するHTMLのコード
-->
</noscript>
</body>
</html>


window.alert( )→警告ダイアログを表示

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


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>警告ダイアログ</title>
</head>
<body>
<script type="text/javascript">
<!--
  window.alert( 'ありがとう!' );
// -->
</script>
<noscript>
  JavaScript対応ブラウザで表示してください。
</noscript>
</body>
</html>




<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>メソッド</title>
</head>
<body>
<p>ボタンをダブルクリックしてください。
<input type="button" value="ボタン" onClick="alert( 'Perfect!' )">
</p>
</body>
</html>