ajax

1.musical_dyn_keys.css
.musicalKeys{
 background-color:#ffe0d0;
 border:solid maroon 2px;
 position:absolute;
 overflow:auto;
 margin:4px;
}
.toplong{
 width:536px;
 height:68px;
 top:24px;
 left:24px;
}
.sidebar{
 width:100px;
 height:400px;
 top:24px;
 left:570px;
}
.musicalButton{
 border:solid navy 1px;
 width:60px;
 height:60px;
 position:relative;
 margin:2px;
 float:left;
}
.do{background-color:red;}
.re{background-color:orange;}
.mi{background-color:yellow;}
.fa{background-color:green;}
.so{background-color:blue;}
.la{background-color:indigo;}
.ti{background-color:violet;}
div.console{
 font-family:arial,helvetica;
 font-size:16px;
 color:navy;
 background-color:white;
 border:solid navy 2px;
 width:536px;
 height:320px;
 top:106px;
 left:24px;
 margin:4px;
 position:absolute;
 overflow:auto;
}

2.musical_dyn_keys.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Two Keyboards</title>
  <LINK rel='stylesheet' type='text/css' href='musical_dyn_keys.css'/>
  <SCRIPT type='text/javascript' src='musical_dyn_keys.js'></SCRIPT>
  <SCRIPT type='text/javascript'>
   window.onload=assignKeys
  </SCRIPT>
 </head>
 <body>
  <DIV id='keyboard-top' class='toplong musicalKeys'></DIV>
  <DIV id='keyboard-side' class='sidebar musicalKeys'></DIV>
  <DIV id='console' class='console'></DIV>
 </body>
</html>


3.musical_dyn_keys.js
var notes = new Array("do","re","mi","fa","so","la","ti","do");
function assignKeys(){
 var candidates = document.getElementsByTagName("DIV");
 if(candidates){
  for(var i=0;i<candidates.length;i++){
   var candidate = candidates[i];
   if(candidate.className.indexOf('musicalKeys')>=0){
    makeKeyboard(candidate);
   }
  }
 }
}

function makeKeyboard(el){
 for(var i=0;i<notes.length;i++){
  var key=document.createElement("DIV");
  key.className = notes[i] + " musicalButton";
  alert(key.className);
  key.note = notes[i];
  key.onclick = playNote;
  el.appendChild(key);
 } 
}

function playNote(event){
 var note = this.note;
 var console = document.getElementById('console');
 if(note && console){
  console.innerHTML +=note + ".";
 }
}

posted on 2006-08-11 11:34 software5168 阅读(306) 评论(0)  编辑  收藏 所属分类: Java學習


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年8月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

收藏夹

JAVA學習網站

綜合

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜