我已经完成了完整的解决方案箱。所以,我在这里放置了演示链接,如下所示:
演示: http ://codebins.com/bin/4ldqp9r
HTML:
<div id="panel">
<div class="quiz">
<span class="header">
Div-1
</span>
<p>
Question-1?
<input type="text" tabIndex="1" />
</p>
<p>
Question-2?
<input type="text" tabIndex="2" />
</p>
<p>
Question-3?
<input type="text" tabIndex="3" />
</p>
</div>
<div class="quiz">
<span class="header">
Div-2
</span>
<p>
Question-4?
<input type="text" tabIndex="4" />
</p>
<p>
Question-5?
<input type="text" tabIndex="5" />
</p>
<p>
Question-6?
<input type="text" tabIndex="6" />
</p>
</div>
</div>
CSS:
.header{
border-bottom:1px solid #445599;
display:block;
background:#447797;
padding:0px;
}
.quiz{
background:#bbaadd;
border:1px solid #445599;
padding:2px;
display:inline-block;
}
.quiz input{
border:1px solid #113388;
}
.quiz input:focus{
background:#d98866;
}
查询:
$(function() {
$(".quiz:first input:first").focus();
$(".quiz input").keypress(function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
if ($(this).parents(".quiz").next().find("input:first").length > 0) {
$(this).parents(".quiz").next().find("input:first").focus();
/*
//OR Another way to find next input selector is:
$(this).closest(".quiz").next().find("input:first").focus();
*/
} else if ($(this).parents(".quiz").prev().find("input:first").length > 0) {
$(this).parents(".quiz").siblings(".quiz:first").find("input:first").focus();
/*
//OR Another way to find next input selector is:
$(this).closest(".quiz").siblings(".quiz:first").find("input:first").focus();
*/
}
}
});
});
演示: http ://codebins.com/bin/4ldqp9r