我的要求是gridview可编辑列中的箭头键导航。 现在它正在使用以下代码。
现在我想阻止箭头键移动到tabindex =-1
(不可编辑)的列。
怎么做?
我的源代码如下所述
<script src="JQuery/jquery.keynavigation.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var gridview = $("#grdView");
$.keynavigation(gridview);
});
</script>
jQuery.keynavigation = function(table) {
var rowColorStyle = "BACKGROUND-COLOR: white; COLOR: #003399";
var rowHighlightColor = "#aaa";
table.find("input[type='text'],input[type='checkbox'], select").keydown(
function(event) {
if ((event.keyCode == 39) ) {
var inputs = $(this).parents("table").eq(0).find("input[type='text'],input[type='checkbox'], select");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
inputs[0].select()
} else {
$(this).parents("table").eq(0).find("tr").not(':first').each(function() {
});
inputs[idx + 1].focus();
inputs[idx].value = inputs[idx].value;
if (inputs[idx + 1].type != "select-one") {
inputs[idx + 1].select();
}
}
event.preventDefault();
}
if ((event.keyCode == 37) ) {
var inputs = $(this).parents("table").eq(0).find("input[type='text'],input[type='checkbox'], select");
var idx = inputs.index(this);
if (idx > 0) {
$(this).parents("table").eq(0).find("tr").not(':first').each(function() {
});
inputs[idx - 1].focus();
inputs[idx].value = inputs[idx].value;
if (inputs[idx - 1].type != "select-one")
{ inputs[idx - 1].select(); }
}
event.preventDefault();
}
});
table.find("input[type='text'],input[type='checkbox']").keydown(
function(event) {
if ((event.keyCode == 40)) {
if ($(this).parents("tr").next() != null) {
var nextTr = $(this).parents("tr").next();
var inputs = $(this).parents("tr").eq(0).find("input[type='text'],input[type='checkbox']");
var idx = inputs.index(this);
nextTrinputs = nextTr.find("input[type='text'], input[type='checkbox']");
if (nextTrinputs[idx] != null) {
$(this).parents("table").eq(0).find("tr").not(':first').each(function() {
});
nextTrinputs[idx].focus();
nextTrinputs[idx].value = nextTrinputs[idx].value;
if (nextTrinputs[idx].type != "select-one")
{ nextTrinputs[idx].select(); }
}
}
else {
$(this).focus();
if ($(this).type != "select-one")
{ $(this).select(); }
}
event.preventDefault();
}
if ((event.keyCode == 38)) {
if ($(this).parents("tr").prev() != null) {
var nextTr = $(this).parents("tr").prev();
var inputs = $(this).parents("tr").eq(0).find("input[type='text'],input[type='checkbox']");
var idx = inputs.index(this);
nextTrinputs = nextTr.find("input[type='text'],input[type='checkbox']");
if (nextTrinputs[idx] != null) {
$(this).parents("table").eq(0).find("tr").not(':first').each(function() {
});
nextTrinputs[idx].focus();
nextTrinputs[idx].value = nextTrinputs[idx].value;
if (nextTrinputs[idx].type != "select-one")
{ nextTrinputs[idx].select(); }
}
return false;
}
else {
$(this).focus();
if ($(this).type != "select-one")
{ $(this).select(); }
}
event.preventDefault();
}
});
//Navigate to the next same column in the next row when the enter key is clicked.
table.find("input[type='text'], input[type='checkbox'], select").keypress(
function(event) {
if (event.keyCode == 13) {
if ($(this).parents("tr").next() != null) {
var nextTr = $(this).parents("tr").next();
var inputs = $(this).parents("tr").eq(0).find("input[type='text'], input[type='checkbox'], select");
var idx = inputs.index(this);
nextTrinputs = nextTr.find("input[type='text'], input[type='checkbox'], select");
if (nextTrinputs[idx] != null) {
$(this).parents("table").eq(0).find("tr").not(':first').each(function() {
});
nextTrinputs[idx].focus();
if (nextTrinputs[idx].type != "select-one")
{ nextTrinputs[idx].select(); }
}
return false;
}
else {
$(this).focus();
if ($(this).type != "select-one")
{ $(this).select(); }
}
event.preventDefault();
}
});
}