javaScript实现背景音乐与播放声音
研究了半天,不过貌似还是只能在IE上实现,其他浏览器不支持EMBED 标签
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用javascript制作超链接的背景音效</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function controlSound(action)
{
var i; method = "";
var sndObj = document.getElementById("music");
if (sndObj != null)
{
if (navigator.appName == 'Netscape')
method = "play";
else
{
if (window.MM_WMP == null)
{
window.MM_WMP = false;
for(i in sndObj)
{
if (i == "ActiveMovie")
{
window.MM_WMP = true;
//alert("1");
break;
}
}
}
if (window.MM_WMP)
method = "play";
else if (sndObj.FileName)
method = "run";
}
}
if (method)
{
if(action=="stop")
method="stop";
alert(method);
eval("document.hidden_player"+"."+method+"()");
}
}
//-->
</script>
</head>
<body>
<a href="#" onMouseOver="controlSound('play','document.ailisi','2.mp3')"
onmouseout="controlSound('stop','document.ailisi','2.mp3')"
>背景音乐 鼠标移入播放 移出停
</a> <br>
<button onclick="controlSound('play')">播</button>
<button onclick="controlSound('stop')">停</button>
<!--src是音频的地址, hidden属性为隐藏-->
<EMBED NAME='hidden_player' SRC='1.wma
相关文档:
window
window对象是浏览器或者框架自身.top总是浏览器,parent是父框架,self表示自己.
window通常可以省略.
窗口操作: moveBy(dx, dy), moveTo(x, y),
resizeBy(dw, dh), resizeTo(w, h).
导航: window.open(url, frame
name, attribute). attribute可以是left, top, height, width, resizable,
scrollable, too ......
正则表达式
RegExp(regexp, option)类实现,可以简写成/regexp/option
option:
g: global, i: ignore case
方法:string.test(regexp),
string.exec(regexp)[返回所有匹配的地方], string.serch(regexp)[正则版的indexOf()],
string.replace(regexp, str|funtion), string.split(regexp)
简单模式
元字符:( [ {
......
//1.类
function Test(id)
{
this.id=id;
this.method=function()
{
//代码
};
}
......
自己写的一个简易计时器,能记算代码的执行时间,还可以拿来测试代码的执行效率。
function Counter(){
this.start();
}
Counter.prototype.getTime = function(){
var time = new Date();
return time.getSeconds()*1000+time.getMilliseconds();
}
Counter.prototype.start = function(){
this. ......