<script language="JavaScript">
var isNN = (navigator.appName.indexOf("Netscape") != -1);
document.onkeyup = autoTab;
document.onkeydown = blockEnter;
function autoTab() {
var e = event;
var input = event.srcElement;
var keyCode = (isNN) ? e.which : e.keyCode;
if (keyCode == 13 && input.type!="textarea") {
if (getNextIndex(input) > -1)
input.form[(getNextIndex(input)) % input.form.length].focus();
}
}
function containsElement(arr, ele) {
var found = false, index = 0;
while (!found && index < arr.length)
if (arr[index] == ele)
found = true;
else
index++;
return found;
}
function getNextIndex(input) {
var index = -1, i = 0,j=0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input) {
j = i + 1;
while (j < input.form.length && index == -1) {
if (input.form[j].type == "text" || input.form[j].type == "textarea") index = j;
else j++;
}
return index;
}
else i++;
}
function blockEnter(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode :
((evt.which) ? evt.which : evt.keyCode);
if (charCode == 13) {
var input = event.srcElement;
if (input.type != "textarea") return false;
} else {
return true;
}
}
</script>
沒有留言:
張貼留言