Simplified Enter into TAB components

xiaoxiao2021-03-05  23

/ **************************************************

*

* Author: dbpeng

* Uses: Enter transforms into tab

* Use: onload = "initener2tab ()" Form mark plus

...

*

* /

VAR iscycle = false; // Whether the cursor is focusing when the cursor is at the last element,

Var icrrent = -1;

Var fmname = "0" // input_form

//

Function Entertainment Entertainment Entertainment Entertainment Entertainment Transfer

{

Var E = Document.ActiveElement;

IF (e == null) Return False;

// Get the name of the current form

For (i = 0; i

For (var El in Document.Forms [i] .Elements) {

IF (E.UniqueID == El.uniqueID) {

FRMNAME = Document.Forms [i] .name

}

}

}

IF (Window.Event.Keycode == 13)

{

Switch (e.tagname) // Type

{

Case "Input":

Handleinput (e)

Break;

Case "SELECT":

Handleselect (e)

Break;

Case "Textarea":

HandletextArea (e)

Break;

DEFAULT:

//Window.status = "Unknown tag name:" e.tagname ", can not move the focus!"

}

} // end if

}

// Handling the INPUT tag type

Function HandleInput (e)

{

Switch (E.TYPE)

{

Case "text":

Case "Password":

Case "Checkbox":

Case "Radio":

Case "file":

MovefocustOnexTelement (e)

Break;

CASE "submit": // Handling the situation with the commit button

Case "Button":

IF (iShandLesubmit (e)) {

Handlesubmit (e)

FocusonnexTelement (Document.Forms [frmname] .Elements, Icurrent-1)

Break;

}

MovefocustOnexTelement (e)

Break;

DEFAULT:

}

}

// Handle the SELECT tag type

Function Handleselect (e)

{

MovefocustOnexTelement (e)

}

// Treat TEXTAREA Tag Type

Function HandletExtArea (e)

{

MovefocustOnexTelement (e)

}

// Move to the next element

Function MovefocustOnexTelement (E)

{

Var OE = Document.Forms [frmname] .Elements, iCurentPos = -1;

For (VAR i = 0; i

IF (OE [i] == e) icrentpos = i;

If (IcurentPos> -1 && icuntPos 1

{

// Set the focus to the next available element

FocusonnexTelement (OE, IcurentPos)

}

}

}

/ / The next available element is obtained from the position of the focus n element

Function FocusonnexTelement (Olements, IIndex)

{

Var OE = Olements

Var OldIndex = IIndex

While (OE [IIndex 1] .Type == "Hidden" || OE [IIndex 1] .disabled || OE [IIndex 1] .readOnly == True || OE [IIndex 1] .Style.display == "none")

{

/ *

WINDOW.STATUS = "E.NAME =" OE [IINDEX 1] .Name

WINDOW.STATUS = "; e.type =" OE [IINDEX 1] .type

WINDOW.STATUS = "; E.disabled =" OE [IIndex 1] .disabled

WINDOW.STATUS = "; E.Readonly =" OE [IINDEX 1] .readonly "."

* /

IINDEX ;

IF (IINDEX 1 == OE.LENGTH)

{

IF (iScycle) {// set focus in the first element

FocusonnexTelement (OE, -1)

}

Return;

}

} // End while

Icurrent = IIndex 1

OE [icrrent] .focus ();

Window.event.keycode = 0;

Window.Event.ReturnValue = false;

Return;

}

// Treat the current element

Function HandleSubmit (Element)

{

Element.click ()

Return;

}

/ / Judgment whether or not processing commit

Function ishandLesubmit (Element)

{

Var rett = false;

IF (element! = null& () == "submit" || Element.name.touppercase () == "Submit" | Element.issubmit)) {

Ret = true;

}

Return Ret;

}

// Initialization inTenter2Tab ()

Function initener2tab ()

{

For (i = 0; i

IF (Document.Forms [i] .Type! = null && document.forms [i] .type == "enter2tab") {

Document.forms [i] .onkeydown = function f () {entertotab ();};

}

// Document initialization focus

IF (Document.Forms [0] .Elements! = null)

Focusonnextelement (Document.Forms [0] .Elements, -1)

}

转载请注明原文地址:https://www.9cbs.com/read-39392.html

New Post(0)