2017-07-20 6 views
1

Kann mir bitte jemand sagen, warum die keydown Funktion von JavaScript in Internet Explorer 11 nicht funktioniert? Ich möchte nicht $(document).keydown verwenden, da es immer feuern wird. Ich möchte die keydown auf nur ein Textfeld beschränken.Keydown-Funktion funktioniert nicht in Internet Explorer 11

Es folgt der Code

$('#country-name').on('keydown', function(e) { 

    if (e.which == 40) { 
    var totalCountries = $("a.anchor:visible").length; 

    window.count = parseInt($("#counter").text()); 

    if (window.count >= totalCountries) { 
     console.log('hi'); 
     $("#counter").text("0"); 
     $(".scroll-control")[0].focus(); 
     e.preventDefault(); 
     return; 
    } 


    $("a.anchor:visible")[window.count].focus(); 

    window.count = window.count + 1; 

    $("#counter").text(window.count); 

    e.preventDefault(); 

    console.log(window.count); 
    } 

}); 


$('.country').keydown(function(e) { 
    if (e.which == 40) { 

    var totalCountries = $("a.anchor:visible").length; 

    window.count = parseInt($("#counter").text()); 

    if (window.count >= totalCountries) { 
     console.log('hi'); 
     $("#counter").text("0"); 
     $(".scroll-control")[0].focus(); 
     e.preventDefault(); 
     return; 
    } 


    $("a.anchor:visible")[window.count].focus(); 

    window.count = window.count + 1; 

    $("#counter").text(window.count); 



    e.preventDefault(); 


    console.log(window.count); 
    } 

}); 

Antwort

0

Sie benötigen weitere Informationen über den Kontext (der HTML-Teil) und das genaue Problem zu geben.

Hier ist eine einfache Geige, dass zeigt keyDown in IE 11 für bestimmte Eingaben funktioniert:

$('.checkKeydown, #area1').on('keydown', function(e) { 
 
    if (e.which == 40) { 
 
    $("#result1").html('detected in ' + e.target.type); 
 
    } 
 
}); 
 

 
$('.checkKeydown, #area1').keydown(function(e) { 
 
    if (e.which == 40) { 
 
    $("#result2").html('detected in ' + e.target.type); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<select class="checkKeydown"> 
 
    <option>Press Down key...</option> 
 
</select> 
 
<input class="checkKeydown" placeholder="Press down key..." /> 
 
<textarea id="area1" placeholder="Press down key..."></textarea> 
 
<input placeholder="Not handled..." /> 
 
<br/> on.('keydown') : <span id='result1'></span> 
 
<br/> .keydown : <span id='result2'></span>

+0

Es war das Cache-Problem im Internet Explorer. Gelöst. –

Verwandte Themen