首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >切换代码在Internet Explorer、Safari中不起作用,但在Chrome和Firefox中起作用

切换代码在Internet Explorer、Safari中不起作用,但在Chrome和Firefox中起作用
EN

Stack Overflow用户
提问于 2014-12-26 11:55:17
回答 1查看 102关注 0票数 0

这段代码在两张图片之间来回切换,在Chrome和Firefox中运行良好,但在Internet Explorer或Safari中不起作用。你知道我做错了什么吗?

谢谢

这是我们的网站。http://readautism.atwebpages.com/index3.html

代码语言:javascript
复制
<!doctype html>
    <html>
    <head>
    <meta charset="ISO-8859-1" />
    <title>Example of How to Play a Sound on Click or on MouseOver</title>
    <script>

    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(){
                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('http://static.sfdict.com/staticrep/dictaudio/P05/P0501900.mp3', "whistle.ogg")
    var uniquevar=createsoundbite("bus.wav", "whistle.ogg", "whistle.mp3")
    var uniquevar1=createsoundbite("pizza.wav", "whistle.ogg", "whistle.mp3")
    var uniquevar2=createsoundbite("can.wav", "whistle.ogg", "whistle.mp3")
    </script>
    <script>
    var gStorage = {};

    function toggle(anImage, anAltSrcArr) {
        if (typeof(anImage) === "undefined" || typeof(anAltSrcArr) === "undefined" || anAltSrcArr.length === 0) {
            return;
        }

        var id = anImage.id;
        var oldSrc = anImage.src;

        if (typeof(gStorage[id]) === "undefined") {
            gStorage[id] = {
                'id': id,
                'origSrc': oldSrc,
                'i': 0
            };
        }

        gStorage[id].i += 1;
        if (gStorage[id].i > anAltSrcArr.length) {
            gStorage[id].i = 0;
        }

        if (gStorage[id].i === 0) {
            anImage.src = gStorage[id].origSrc;
        } else {
            anImage.src = anAltSrcArr[gStorage[id].i - 1];
        }
    }
    </script>
    </head>
    <body
    <p>

    <img class="with-action" id="image1" name="image1" src="pizza.jpg" onclick="uniquevar1.playclip();toggle(this, ['pizza1.jpg'])" STYLE="position:absolute; TOP:95px; LEFT:70px; WIDTH:150px; HEIGHT:150px"/>
    <img class="with-action" id="image2" name="image2" src="can.jpg" onclick="uniquevar2.playclip();toggle(this, ['can1.jpg'])" STYLE="position:absolute; TOP:95px; LEFT:370px; WIDTH:150px; HEIGHT:150px"/>
    <img class="with-action" id="image3" name="image3" src="bus.jpg" onclick="uniquevar.playclip();toggle(this, ['bus1.jpg'])" STYLE="position:absolute; TOP:95px; LEFT:670px; WIDTH:150px; HEIGHT:150px"/>
    </p>
    </body>
    </html>
EN

回答 1

Stack Overflow用户

发布于 2014-12-26 12:08:18

它在我的Safari中运行良好,你有没有尝试过,重新启动或重新启动Safari。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27652666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档