问题
I just have button in a page and nothing else
<button>hello</button>
When I open the page and press tab it comes to button but instead I want it in such a way that if I hit enter it should come to that button.
This is the code that I have written but it is not working
$(document).ready(function () {
$('.EntTab').on('keydown', function (e) {
if (e.keyCode == 13) e.keyCode = 9;
return false;
});
});
Need help in tackling this.
回答1:
Check this!
$(function() {
$(document).keydown(function(e) {
if (e.keyCode == 13) {
$("button#hel").focus();
} else if (e.keyCode == 9) {
var e = jQuery.Event("keydown", {
keyCode: 9
});
$(document).trigger(e);
}
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="hel">hello</button>
<button>hello</button>
<button>hello</button>
来源:https://stackoverflow.com/questions/36398003/enter-button-works-as-tab