DHTML
DHTML is a good thing. It greatly enhances the front-end interaction implementation, making it extremely simple to get page elements and modify page elements dynamically. But do all browsers know these syntaxes?
Document. all
Document. all is not recognized by all browsers. To write more common code, you 'd better use the id to get it. Use document. getElementById (...)
Element. outerText, element. innerText, element. outerHTML, element. innerHTML
Element. outerText, element. innerText, and element. outerHTML are unique to IE, while element. innerHTML is common.
If you want to use non-generic properties in other browsers, refer to the following code:
Copy codeThe Code is as follows:
If (! IsIE ()){
HTMLElement. prototype. _ defineGetter _ ("innerText ",
Function (){
Var anyString = "";
Var childS = this. childNodes;
For (var I = 0; I <childS. length; I ++ ){
If (childS [I]. nodeType = 1)
AnyString + = childS [I]. innerText;
Else if (childS [I]. nodeType = 3)
AnyString + = ahildS [I]. nodeValue;
}
Return anyString;
}
);
HTMLElement. prototype. _ defineSetter _ ("innerText ",
Function (sText ){
This. textContent = sText;
}
);
}
Document. forms. actionForm. inputName. value
Document. all. title. value to obtain the value of the title input field in the form named actionForm. It should be changed to document. forms. actionForm. input. to use this method, make sure that the form tag in HTML has a complete closed relationship with other tag structures.
Table operations
MoveRow (iSource, iTarget) Method
ORow = tableObject. moveRow (iSource, iTarget). This method can easily adjust the dynamic sequence of tr in table. But this method is implemented by the IE kernel itself, not the DOM standard method, so no other browsers. To use these methods that are unique to IE, either use the standard DOM node control method-insertBefore (currobj, beforeObj. nextSibling), or first implement a moveRow method on the prototype of the HTMLDocument class:
Copy codeThe Code is as follows:
Function getTRArray (){
......
// Put the tr to be manipulated into an array as the return value of this method
}
Function getTRByIndex (sourceELIndex ){
Var trArray = getTRArray ();
Var result = trArray [sourceELIndex];
Return result;
}
If (! IsIE & HTMLElement. moveRow = null)
{
// Input parameter description:
// SourceELIndex: Specifies the row (> = 1) of the tr to be moved in the tbody)
// TargetELIndex: number of rows to be moved to the tbody (> = 1, <= number of rows)
HTMLElement. prototype. moveRow = function (sourceELIndex, targetELIndex)
{
Var tbObject = document. getElementById ("tbodyEL ");
Var resultEL;
If (sourceELIndex> = targetELIndex)
{// Move up
Var s = sourceELIndex-1;
Var t = targetELIndex-1;
} Else {
Var s = sourceELIndex-1;
Var t = targetELIndex;
}
Var sourceEL = getTRByIndex (s );
Var targetEL = getTRByIndex (t );
// Alert ("begin" + sourceELIndex + targetELIndex );
// Alert ("begin" + s + t );
TbObject. insertBefore (sourceEL, targetEL );
ResultEL = sourceEL;
Return resultEL;
}
}