JS Start, basic

Source: Internet
Author: User

This week began to learn JS, contains a lot of objects, functions

Here's a table I made with a simple delete entire row, modify cell contents, OK and show modified content

<! DOCTYPE html>


<meta charset= "UTF-8" >
<title></title>
<script style= "Text/javascript" >
function fun1 ()//functions 1: The function is to delete the entire row
{
var table = document.getelementsbytagname ("table") [0];
Table.deleterow (0)
}
function fun2 ()//Functions 2: Modify the contents of the cell
{
Table = document.getElementsByTagName ("table") [0]; Find Table Label
Xg= Table.rows[0].cells[0]; Find the cell that you want to modify under the Table tab
Xg.innerhtml= ""//Empty the contents of the Found cell
var input=document.createelement ("input")//Create a new element "input"
Input.type= the property of the "text"//input is text
Input.id = "in1"//Add an ID name to input
Xg.appendchild (input); Inserts a new input text box into a cell

Xg1= Table.rows[0].cells[1]; Ditto, just change the second cell of the row, and insert the input text box again
Xg1.innerhtml= ""
Input=document.createelement ("input")
Input.type= "Text"
Input.id = "In2"
Xg1.appendchild (input);
}
Functions Fun3 ()//function 3: Saves the modified content in function 2 and displays it in the corresponding cell
{
var Zhi=document.getelementbyid ("in1"). Value; Locate the cell with the ID named in1 and receive its value
Xg.textcontent=zhi; The saved value is displayed.
var Zhi1=document.getelementbyid ("in2"). Value; Ditto
Xg1.textcontent=zhi1;
}
function Fun4 ()
{
Table = document.getElementsByTagName ("table") [0];
Table.deleterow (1)
}
function Fun5 ()
{
Table = document.getElementsByTagName ("table") [0];
Xg2= Table.rows[1].cells[0];
Xg2.innerhtml= ""
var input=document.createelement ("Input")
Input.type= "Text"
Input.id = "in3"
Xg2.appendchild (input);

Xg3= Table.rows[1].cells[1];
Xg3.innerhtml= ""
Input=document.createelement ("input")
Input.type= "Text"
Input.id = "In4"
Xg3.appendchild (input);
}
function Fun6 ()
{
var Zhi2=document.getelementbyid ("in3"). Value;
Xg2.textcontent=zhi2;
var Zhi3=document.getelementbyid ("In4"). Value;
Xg3.textcontent=zhi3;
}
function Fun7 ()
{
Table = document.getElementsByTagName ("table") [0];
Table.deleterow (1)
}
function Fun8 ()
{
Table = document.getElementsByTagName ("table") [0];
Xg4= Table.rows[2].cells[0];
Xg4.innerhtml= ""
var input=document.createelement ("Input")
Input.type= "Text"
Input.id = "In5"
Xg4.appendchild (input);

Xg5= Table.rows[2].cells[1];
Xg5.innerhtml= ""
Input=document.createelement ("input")
Input.type= "Text"
Input.id = "In6"
Xg5.appendchild (input);
}
function Fun9 ()
{
var Zhi4=document.getelementbyid ("In5"). Value;
XG4.TEXTCONTENT=ZHI4;
var Zhi5=document.getelementbyid ("In6"). Value;
Xg5.textcontent=zhi5;
}
function Fun10 ()
{
var table = document.getelementsbytagname ("table") [0];
var tr = Table.insertrow (3);
var Td1=tr.insertcell (0);
var Td2=tr.insertcell (1);
var Td3=tr.insertcell (2);
var Td4=tr.insertcell (3);
var Td5=tr.insertcell (4);

Td1.textcontent= ""
Td2.textcontent= ""
Td3.textcontent= ""
Td4.textcontent= ""
Td5.textcontent= ""

var but=document.createelement ("input");
But.type= "button";
But.value= "Delete"
Td3.appendchild (But)

var but1=document.createelement ("input");
But1.type= "button";
But1.value= "Modify"
Td4.appendchild (BUT1)

var but2=document.createelement ("input");
But2.type= "button";
But2.value= "OK"
Td5.appendchild (BUT2)
}

</script>

<body>
<table border= "1" >
<tr>
<td>aaaaaaa11</td>
<td>bbbbbbb</td>
<td> <input type= "button" value= "delete" onclick= "fun1 ()"/></td>
<td> <input type= "button" value= "Modify" onclick= "fun2 ()"/></td>
<td><input type= "button" value= "OK" onclick= "fun3 ()"/></td>
</tr>
<tr>
<td>aaaaaaa22</td>
<td>bbbbbbb</td>
<td> <input type= "button" value= "delete" onclick= "Fun4 ()"/></td>
<td> <input type= "button" value= "Modify" onclick= "Fun5 ()"/></td>
<td><input type= "button" value= "OK" onclick= "fun6 ()"/></td>
</tr>
<tr>
<td>aaaaaaa33</td>
<td>bbbbbbb</td>
<td> <input type= "button" value= "delete" onclick= "fun7 ()"/></td>
<td> <input type= "button" value= "Modify" onclick= "Fun8 ()"/></td>
<td><input type= "button" value= "OK" onclick= "fun9 ()"/></td>
</tr>
<tr>
&LT;TD colspan= "5" style= "Text-align:center" ><input type= "button" value= "Add" onclick= "Fun10 ()"/></td >
</tr>
</table>

</body>

JS Start, basic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.