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
相关文档:
程序设计中会经常碰到一种情况,就是事先无法得知用户会需要哪些数据,必须根据用户选择后再从服务器
重新提取数据后反馈给用户。比如一简单的情况,用户选择省份以后,我们立即会在市里边将这个省的所有
市重新显示出来。这种情况一般需要将整个页面刷新后才可以重新读取,但这样不仅效率不高外,也显得不
太优雅。其实 ......
正则表达式
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)
简单模式
元字符:( [ {
......
先来看一个简单的例子:
下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。
Java代码
frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ......
注册很长时间号了,刚开通博客,拿出一个自己写的javascript右键菜单,兼容IE,firefox浏览器
这是css代码
body{
font-size:12px;
}
.contextMenu{
filter:alpha(opacity=80);
opacity:0.8;
border:1px #0033FF solid;
background-color:#0099CC;
cursor:pointer;
width:120px;
position:absolute;
top: ......
自己写的一个简易计时器,能记算代码的执行时间,还可以拿来测试代码的执行效率。
function Counter(){
this.start();
}
Counter.prototype.getTime = function(){
var time = new Date();
return time.getSeconds()*1000+time.getMilliseconds();
}
Counter.prototype.start = function(){
this. ......