我知道,还有其他问题,即防止Default()不与Peth合作,但无助于我。
I ve got three SELECT lists, and all I want is to navigate between them using the arrow keys without changing any values. The code works great in Chrome, but in Firefox it moves focus and then changes the value on the element just moved to.
JavaScript:
$(document).ready(function () {
$( .myinput ).keydown(function (evt) { onkeydown(evt); });
$( .myinput:first ).focus();
});
function onkeydown(evt) {
evt.preventDefault();
console.log(evt.which);
if(evt.which == 39) {
$(document.activeElement).next().focus();
}
else if(evt.which == 37) {
$(document.activeElement).prev().focus();
}
}
<>光>:
<div id="inputs">
<select class="myinput">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="myinput">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="myinput">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>