jQuery的切换类需要在Internet Explorer中单击两次?

时间:2015-10-10 22:06:02

标签: javascript jquery internet-explorer-11 toggleclass

在Firefox / Chrome / Microsoft Edge中运行良好,但是当在最新的Internet Explorer 11中单击该按钮时,只需要两次单击即可切换类。其他一切都按预期运行(当它应该播放和停止音乐时)。

JSFiddle Example

<script>
$(".play").on('click', function () {
    var key = $(this).attr('key');
    EvalSound(this, key);
    var this_play = $(this);
    $(".play").each(function () {
        if ($(this)[0] != this_play[0]) {
            $(this).removeClass("pause");
        }
    });
    $(this).toggleClass("pause");
});

var thissound = new Audio();
var currentKey;

function EvalSound(el, key) {
    thissound.addEventListener('ended', function () {
        // done playing
        $(el).removeClass("pause");
    });

    if (currentKey !== key) thissound.src = "exclusive/" + key + ".mp3";
    currentKey = key;

    if (thissound.paused) thissound.play();
    else thissound.pause();
    thissound.currentTime = 0;
    currentPlayer = thissound;
}
</script>

1 个答案:

答案 0 :(得分:0)

由于toggleClass通常在IE中工作,我觉得问题只是与编写代码的方式有关:这是JS小提琴中的一键式工作版本:http://jsfiddle.net/jeffd/2fjnmdkb/22/

attrs
相关问题