Javascript jQuery';s切换类需要在Internet Explorer中单击两次?

Javascript jQuery';s切换类需要在Internet Explorer中单击两次?,javascript,jquery,internet-explorer-11,toggleclass,Javascript,Jquery,Internet Explorer 11,Toggleclass,在Firefox/Chrome/MicrosoftEdge中工作得很好,但在最新的InternetExplorer11中单击该按钮时,需要两次单击才能切换类,而实际上只需要一次。其他一切都按它应该的方式执行(它在应该的时候播放和停止音乐) $(“.play”)。在('click',函数(){ var key=$(this.attr('key'); EvalSound(这个,键); 变量this_play=$(this); $(“.play”)。每个(函数(){ 如果($(此)[0]!=此游戏

在Firefox/Chrome/MicrosoftEdge中工作得很好,但在最新的InternetExplorer11中单击该按钮时,需要两次单击才能切换类,而实际上只需要一次。其他一切都按它应该的方式执行(它在应该的时候播放和停止音乐)


$(“.play”)。在('click',函数(){
var key=$(this.attr('key');
EvalSound(这个,键);
变量this_play=$(this);
$(“.play”)。每个(函数(){
如果($(此)[0]!=此游戏[0]){
$(this.removeClass(“暂停”);
}
});
$(this.toggleClass(“暂停”);
});
var thissound=新音频();
var-currentKey;
功能评估声音(el,键){
thissound.addEventListener('ended',函数(){
//玩完
$(el.removeClass(“暂停”);
});
如果(currentKey!==key)thissound.src=“exclusive/”+key+”.mp3”;
currentKey=key;
如果(thissound.暂停)thissound.play();
否则这个声音就会停止;
thissound.currentTime=0;
currentPlayer=此声音;
}

由于toggleClass通常在IE中工作,我认为问题只是与此代码的编写方式有关:以下是JS Fiddle中的IE一键式工作版本:


由于toggleClass通常在IE中工作,我认为问题在于代码的编写方式:这是一个在JS Fiddle中的IE一键工作版本:

<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>
$(".play").on('click', function () {
     var key = $(this).attr('key');
     var this_play = $(this);
     $(".play").each(function () {
         if ($(this)[0] != this_play[0]) {
             $(this).removeClass("pause");
         }
     });
     $(this).toggleClass("pause");
     var player_bottom = $(".playerbottom");
     if (currentKey == key || !player_bottom.hasClass('pausebottom')) {
         player_bottom.toggleClass("pausebottom");
     }
     EvalSound(this, key);
 });
 var thissound = new Audio();
 var currentKey;
 function EvalSound(el, key) {
     thissound.addEventListener('ended', function () {
         // done playing
         $(el).removeClass("pause");
         $(".playerbottom").removeClass("pausebottom");
     });
     if (currentKey !== key) thissound.src = "http://99centbeats.com/1e4cb5f584d055a0992385c1b2155786/" + key + ".mp3";
     currentKey = key;
     if (thissound.paused) thissound.play();
     else thissound.pause();
     //thissound.currentTime = 0;
     currentPlayer = thissound;
 }
$(".volume_slider").slider({
    value  : 75,
    step   : 1,
    range  : 'min',
    min    : 0,
    max    : 100,
    slide  : function(){
        var value = $(".volume_slider").slider("value");
        thissound.volume = (value / 100);
    }
});