次のようにコードをコピーします。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<頭>
<title>シンプルなイベント処理</title>
<meta http-equiv="キーワード" content="キーワード1,キーワード2,キーワード3">
<meta http-equiv="description" content="これは私のページです">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--
<script language="text/javascript" src="hello.html">この JS の外部呼び出しタグは単独で終了できません</script>
<link rel="stylesheet" type="text/css" href="./styles.css">
-->
<script type="text/javascript">
関数 clickD(obj){
アラート(obj.innerHTML);
}
関数mouseD(obj){
obj.style.color = "#f00";
// コードを使用してスタイルを設定する場合、CSS が - で表されている場合は、キャメルケースでマークする必要があります font-size -> fontSize
obj.style.fontSize = "16px";
}
関数 outD(obj){
obj.style.color = "#000";
obj.style.fontSize = "18px";
}
//withの使い方
with(ドキュメント){
write("dddd<br/>");
}
document.write("ああああ<br/>");
document.write("bbbb<br/>");
document.write("cccc<br/>");
</script>
</head>
<本文>
<div onclick="clickD(this)" style="cursor:pointer;">クリックして試してみる</div>
<div onmouseover="mouseD(this)" onmouseout="outD(this)">マウスを動かしてみます</div>
</body>
</html>
2. ブラウザ オブジェクトの例: 「2 つのブラウザ ページ間の値の転送を伴う」
次のようにコードをコピーします。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
「http://www.w3.org/TR/html4/strict.dtd」
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja">
<頭>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js01_hello</title>
<meta name="作成者" content="管理者" />
<script type="text/javascript">
// setTimeout("endWelcome()",5000);
// 関数 endWelcome() {
// document.getElementById("welcome").style.display = "none";
// }
</script>
</head>
<本文>
<div id="welcome">当社のウェブサイトへようこそ</div>
<a href="#" onclick="window.open('test02.html','aaa','width=300,height=300,resizable=0')">テスト02</a>
<a href="#" onclick="window.open('test03.html','aaa','width=400,height=400,resizable=0')">テスト03</a>
<br/>
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')">祝福を入力してください</a>
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')">性別を選択</a>
<div id="bless"></div>
</body>
</html>
次のようにコードをコピーします。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
「http://www.w3.org/TR/html4/strict.dtd」
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja">
<頭>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js01_hello</title>
<meta name="作成者" content="管理者" />
<script type="text/javascript">
関数 bless() {
//入力された祝福の言葉を取得します
var mb = document.getElementById("mb").value;
// 親ウィンドウを取得する
var p = ウィンドウオープナー;
//親ウィンドウでID blessを持つdivを取得します
var pd = p.document.getElementById("bless");
//pdの値を設定する
pd.innerHTML = mb;
// 現在のウィンドウを閉じる
window.close();
}
</script>
</head>
<本文>
祝福の言葉を入力してください:<input type="text" size="40" id="mb"/><input type="button" onclick="bless()" value="input" />
</body>
</html>