javaScript 控制背景音乐

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <bgsound id="bgs" src="music/test.mp3" volume="10" loop="infinite">
        <input id="state" type="button" value="关闭" onclick="change()" />
    </div>
    </form>
</body>
</html>

<script language="javascript" type="text/javascript">
    var bgsPath = document.getElementById("bgs").src;
    function change() {
        var state = document.getElementById("state");
        state.value = state.value == '关闭' ? '打开' : '关闭';
        bgs.src = bgs.src == '' ? bgsPath : '';
    }
</script>

posted @ 2012-12-20 23:51  齐_大圣  阅读(324)  评论(0编辑  收藏  举报