Home > front end >  Javascript simply add or remove record form
Javascript simply add or remove record form

Time:05-05

Important: the DOM querying,



<meta charset="utf-8" & gt;


Window. The onl oad=function () {
/* hyperlinks */delete employees
Let alla=document. GetElementsByTagName (" a ");
The function dela () {
//let the tr=this. ParentNode. ParentNode;
Let mz=this. ParentNode. ParentNode. GetElementsByTagName (" td ") [0]. InnerHTML
Let qr=confirm (" You sure delete the "+ mz +"?" );//the pop-up has cancelled and confirm button prompt box
If (qr) {
This. ParentNode. ParentNode. ParentNode. RemoveChild (this) parentNode) parentNode);
}
/* click on the link will jump 404
At the end of the function return false to cancel the jump */
return false;
}

For (var I=0; I & lt; Alla. Length; I++) {
Alla [I] onclick=dela;
}
Let sub=document. GetElementById (" submit ");
Sub. Onclick=function () {
Let the TAB=document. GetElementById (" TAB ");//get the table form
Let Newman=document. GetElementsByTagName (" input ");//get the input 'array'
Let tbody=TAB. GetElementsByTagName (" tbody ") [0];//get tbody
Let the tr=document. The createElement method (" tr ");//create an empty tr
Let td=document. The createElement method (" td ");//create an empty td
Let a=document. The createElement method (" a ");//create a tag
Let the AD=document. CreateTextNode (" delete ");//create the delete text
For (var I=0; I & lt;=2; I++) {//to get to the inside of the input array value to empty the tr, is input in the input
Tr. InnerHTML +="& lt; Td>" + Newman [I] value + "& lt;/td> ";
}
A.o nclick=dela;//a delete function called
A.h ref="javascript:;"; Can't afford to add//a href points otherwise
A.a ppendChild (AD).//
The tr. The appendChild (td);
Td. The appendChild (a)
The tbody. The appendChild (tr);

}
};
</script>

<body>

Name
Email
Salary















Name
Email & lt; Input type="email" name="" id=" email "value=" "/& gt;

Salary
Submit




  • Related