[新着] Webテンプレートを仮オープンしました
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function chgBG(){
var el = document.forms['frm'].elements['name1'];
if(el.value == 1){
el.style.backgroundColor = 'orange';
}else if(el.value == 2){
el.style.backgroundColor = 'green';}
}
</script>
</head>
<body>
<form name="frm">
<div>
<input type="text" name="name1" maxlength="1" onChange="chgBG()">
</div>
</form>
</body>
</html>
<head>
<title>フォームカラー</title>
<script language="JavaScript">
function chgbgc(){
switch(document.kansai.osaka01.value){
case '1':document.kansai.osaka01.style.backgroundColor = "#FFFF99";
break;
case '2':document.kansai.osaka01.style.backgroundColor = "#CCFF66";
break;
case '3':document.kansai.osaka01.style.backgroundColor = "#99FFFF";
break;
case '4':document.kansai.osaka01.style.backgroundColor = "#FFCCCC";
break;
case '5':document.kansai.osaka01.style.backgroundColor = "#FFCC66";
break;
case '6':document.kansai.osaka01.style.backgroundColor = "#99CCFF";
break;
case '7':document.kansai.osaka01.style.backgroundColor = "#CC99CC";
break;
case '8':document.kansai.osaka01.style.backgroundColor = "#CCCCCC";
break;
case '9':document.kansai.osaka01.style.backgroundColor = "#FF6666";
break;
case '0':document.kansai.osaka01.style.backgroundColor = "#FFFFFF";
break;
}
}
</script>
</head>
<body>
<p>入力すると背景色が変わります。 </p>
<form name="kansai">
<input type="text" style="font-size: 14pt;" name="osaka01" maxlength="1" onChange="chgbgc()">
<input type="text" style="font-size: 14pt;" name="osaka012" maxlength="1" onChange="chgbgc()">
</form>
function chgbgc(obj){
switch(obj.value){
case '1':obj.style.backgroundColor = "#FFFF99";
break;
case '2':obj.style.backgroundColor = "#CCFF66";
break;
case '3':obj.style.backgroundColor = "#99FFFF";
break;
case '4':obj.style.backgroundColor = "#FFCCCC";
break;
case '5':obj.style.backgroundColor = "#FFCC66";
break;
case '6':obj.style.backgroundColor = "#99CCFF";
break;
case '7':obj.style.backgroundColor = "#CC99CC";
break;
case '8':obj.style.backgroundColor = "#CCCCCC";
break;
case '9':obj.style.backgroundColor = "#FF6666";
break;
case '0':obj.style.backgroundColor = "#FFFFFF";
break;
}
}function chgbgc (obj) {
obj.style.backgroundColor = chgbgc.colorList[obj.value];
}
chgbgc.colorList = [ '#ff9', '#cf6', '#9ff', '#fcc', '#fc6', '#9cf', 'c9c', '#ccc', '#f66', '#fff' ];function chgbgc (obj) {
var c;
switch (obj.value) {
case '1' : c = '#ff9'; break;
case '2' : c = '#cf6'; break;
// 中略
}
obj.style.backgroundColor = c;
}