Javascript 削减开支;粘贴HTML5鼠标覆盖/点击音效脚本

Javascript 削减开支;粘贴HTML5鼠标覆盖/点击音效脚本,javascript,Javascript,我正在使用此网站上发布的以下脚本: 它工作得很好,但是我想扩展这个脚本并使用复选框使声音静音。此复选框的id为:sound。如果选中,我希望听到声音,如果不选中,则不应听到声音 这是我当前用于复选框的代码: 代码: 有人知道怎么做吗 非常感谢 函数muteIt(box){ 如果(单击声音){ clicksound.muted=框。选中?真:假; } 如果(鼠标翻转){ mouseoversound.muted=box.checked?真:假; } } 函数muteIt(box){ 如果(单击声

我正在使用此网站上发布的以下脚本:

它工作得很好,但是我想扩展这个脚本并使用复选框使声音静音。此复选框的id为:sound。如果选中,我希望听到声音,如果不选中,则不应听到声音

这是我当前用于复选框的代码: 代码:

有人知道怎么做吗

非常感谢

函数muteIt(box){ 如果(单击声音){ clicksound.muted=框。选中?真:假; } 如果(鼠标翻转){ mouseoversound.muted=box.checked?真:假; } }

函数muteIt(box){ 如果(单击声音){ clicksound.muted=框。选中?真:假; } 如果(鼠标翻转){ mouseoversound.muted=box.checked?真:假; } }


//鼠标悬停/点击音效-通过JavaScript工具包(www.javascriptkit.com)
//访问JavaScript工具包http://www.javascriptkit.com/ 获取完整的源代码
//**用法:通过调用:var uniquevar=createsoundbite(“soundfile1”、“fallbackple2”、“fallbacksound3”等)实例化脚本
//**调用:uniquevar.playclip()播放声音
var html5_audiotypes={//定义音频文件扩展名及其关联音频类型的列表。如果指定的音频文件不在此列表中,请添加到该列表:
“mp3”:“音频/mpeg”,
“mp4”:“音频/mp4”,
“ogg”:“音频/ogg”,
“wav”:“音频/wav”
}
函数createsoundbite(声音){
var html5audio=document.createElement('audio')
if(html5audio.canPlayType){//检查对html5audio的支持
对于(变量i=0;i

//鼠标悬停/点击音效-通过JavaScript工具包(www.javascriptkit.com)
//访问JavaScript工具包http://www.javascriptkit.com/ 获取完整的源代码
//**用法:通过调用:var uniquevar=createsoundbite(“soundfile1”、“fallbackple2”、“fallbacksound3”等)实例化脚本
//**调用:uniquevar.playclip()播放声音
var html5_audiotypes={//定义音频文件扩展名及其关联音频类型的列表。如果指定的音频文件不在此列表中,请添加到该列表:
“mp3”:“音频/mpeg”,
“mp4”:“音频/mp4”,
“ogg”:“音频/ogg”,
“wav”:“音频/wav”
}
函数createsoundbite(声音){
var html5audio=document.createElement('audio')
if(html5audio.canPlayType){//检查对html5audio的支持
对于(var i=0;i
function playSound() {
    if (document.getElementById('sound').checked){
        -something needs to be added here to make it work?-
    }
}
<script>

// Mouseover/ Click sound effect- by JavaScript Kit (www.javascriptkit.com)
// Visit JavaScript Kit at http://www.javascriptkit.com/ for full source code

//** Usage: Instantiate script by calling: var uniquevar=createsoundbite("soundfile1", "fallbackfile2", "fallebacksound3", etc)
//** Call: uniquevar.playclip() to play sound   

var html5_audiotypes={ //define list of audio file extensions and their associated audio types. Add to it if your specified audio file isn't on this list:
    "mp3": "audio/mpeg",
    "mp4": "audio/mp4",
"ogg": "audio/ogg",
"wav": "audio/wav"
}

function createsoundbite(sound){
    var html5audio=document.createElement('audio')
    if (html5audio.canPlayType){ //check support for HTML5 audio
        for (var i=0; i<arguments.length; i++){
            var sourceel=document.createElement('source')
            sourceel.setAttribute('src', arguments[i])
            if (arguments[i].match(/\.(\w+)$/i))
                sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
            html5audio.appendChild(sourceel)
        }
        html5audio.load()
        html5audio.playclip=function(){
                    if (document.getElementById('sound').checked){

                html5audio.pause()
                    html5audio.currentTime=0
                    html5audio.play()

                    }
        }
    return html5audio
}
else{
    return {playclip:function(){throw new Error("Your browser doesn't support    HTML5 audio unfortunately")}}
}
}

//Initialize two sound clips with 1 fallback file each:

var mouseoversound=createsoundbite("whistle.ogg", "whistle.mp3")
var clicksound=createsoundbite("click.ogg", "click.mp3")

</script>