From: http://blog.csdn.net/fxh_hua/article/details/4433682 to find your own convenience
1. Create a link
<Body>
<Script language = "JavaScript">
VaR o = Document. Body;
// Create a link
Function createa (URL, text)
{
VaR A = Document. createelement ("");
A. href = URL;
A. innerhtml = text;
A. style. color = "red ";
O. appendchild ();
}
Createa ("http://www.hao123.com/", "hao ");
</SCRIPT>
</Body>
2. Create a div <Body>
<Script language = "JavaScript">
VaR o = Document. Body;
// Create a div
Function creatediv (text)
{
VaR DIV = Document. createelement ("Div ");
Div. innerhtml = text;
Div. style. Background = "red ";
O. appendchild (DIV );
}
Creatediv ("Div ");
</SCRIPT>
</Body>
3. Create a form item <Body>
<Script language = "JavaScript">
VaR o = Document. Body;
// Create a form item
Function createinput (stype, svalue)
{
VaR input = Document. createelement ("input ");
Input. type = stype;
Input. value = svalue;
O. appendchild (input );
}
Createinput ("button", "AA ");
</SCRIPT>
</Body>
4. Create a table <Body>
<Script language = "JavaScript">
VaR o = Document. Body;
// Create a table
Function createtable (W, H, R, c)
{
VaR table = Document. createelement ("table ");
VaR tbody = Document. createelement ("tbody ");
Table. width = W;
Table. Height = h;
Table. Border = 1;
For (VAR I = 1; I <= r; I ++)
{
VaR TR = Document. createelement ("TR ");
For (VAR j = 1; j <= C; j ++)
{
VaR TD = Document. createelement ("TD ");
TD. innerhtml = I + "" + J;
// TD. appendchild (document. createtextnode (I + "" + j ));
TD. style. color = "# ff0000 ";
Tr. appendchild (TD );
}
Tbody. appendchild (TR );
}
Table. appendchild (tbody );
O. appendchild (table );
}
Createtable (270,270 );
</SCRIPT>
</Body>
4. Create a button, text box, and input values in the form (Htmlpage1.htm) <SCRIPT type = "text/JavaScript">
VaR Index = 2; Function addele (){
VaR TXT = Document. createelement ("input ");
TXT. setattribute ("type", "input ");
TXT. setattribute ("ID", "TXT" + index ); VaR BTN = Document. createelement ("input ");
BTN. setattribute ("type ","'");
BTN. setattribute ("ID", "BTN" + index );
BTN. setattribute ("value", "value ");
BTN. setattribute ("onclick", "OpenWindow ()"); VaR BR = Document. createelement ("Br "); Document. getelementbyid ("content"). appendchild (txt );
Document. getelementbyid ("content"). appendchild (BTN );
Document. getelementbyid ("content"). appendchild (BR ); Index ++; } Function OpenWindow (){
VaR returnval = Window. showmodaldialog ("htmlpage2.htm ","","");
VaR srcid = Window. event. srcelement. ID; // the object that triggers the event.
VaR ind = srcid. substr (3, srcid. Length );
For (var I in returnval ){
Document. getelementbyid ("TXT" + IND). Value + = returnval [I] + "";
}
}
</SCRIPT>Htmlpage2.htm <Script Type = "text/JavaScript">
Function Sub (){
VaR arr = Document. getelementsbytagname ("input ");
Var val = new array ();
For (var I in ARR ){
If (ARR [I]. type = "checkbox "){
If (ARR [I]. Checked ){
Val [Val. Length] = arr [I]. value;
}
}
}
Window. returnvalue = val;
Window. Close ();
}
</SCRIPT>