1. Create a link
Copy codeThe Code is as follows:
<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.jb51.net/", "niu cwang ");
</Script>
2. Create a DIV
Copy codeThe Code is as follows:
<Script language = "javascript">
Var o = document. body;
// Create a DIV
Function createDIV (text)
{
Var div = document. createElement ("div ");
Div. innerHTML = text;
O. appendChild (div );
}
CreateDIV ("niu cwang: http://www.jb51.net /");
</Script>
3. Create a form item
Copy codeThe Code is as follows:
<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", "ooo ");
</Script>
4. Create a table
Copy codeThe Code is as follows:
<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>