& lt; HTML lang="en" & gt;
& lt; head>
& lt; Meta charset="utf-8" & gt;
& lt; Meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
& lt; Meta HTTP - equiv="X - UA - Compatible" content="ie=edge" & gt;
& lt; title> Document
& lt; Style>
The box {
Width: 1000 px;
height: 30px;
}
Table {
Width: 800 px;
border: 1px solid black;
border-collapse: collapse;
Border - spacing: 0;
}
Thead th,
Td {
border: 1px solid black;
height: 20px;
}
& lt;/style>
& lt;/head>
& lt; body>
& lt; Div & gt;
Name: & lt; Input type="text" & gt;
Age: & lt; Input type="text" & gt;
Income: & lt; Input type="text" & gt;
Operation: & lt; Input type="text" & gt;
& lt;/div>
& lt; Button> Click & lt;/button>
& lt; Table>
& lt; Thead>
& lt; Tr>
& lt; Th> Name & lt;/th>
& lt; Th> Age & lt;/th>
& lt; Th> Income & lt;/th>
& lt; Th> Operation & lt;/th>
& lt;/tr>
& lt;/thead>
& lt; Tbody>
& lt;/tbody>
& lt;/table>
& lt; script>
Var BTN=document. QuerySelector (" button ");
Var tbody=document. QuerySelector (' tbody ');
Var a=document. QuerySelector (' a ');
Var b=document. QuerySelector (' b ');
Var c=document. QuerySelector (' c ');
Var d=document. QuerySelector (' d ');
//click after judging
BTN. AddEventListener (' click ', function () {
If (Dr. Alue!=='& amp; & B.v alue!=='& amp; & C. alue!=='& amp; & D.v alue!=' ') {
Var tr=document. The createElement method (' tr);
Var TRR=tbody. The appendChild (tr);
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=Dr. Alue.
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=b.v alue.
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=c. alue.
Var td=document. The createElement method (" td ");
//td. InnerHTML='& lt; A href="https://bbs.csdn.net/topics/#" & gt; Delete & lt;/a> '
The tr. The appendChild (td);
Td. InnerHTML=d.v alue + '& lt; A href="https://bbs.csdn.net/topics/#" & gt; Delete & lt;/a> ';
}
Var aa=document. QuerySelectorAll (' a ');
For (var I=0; I & lt; Aa. Length; I++) {
Aa [I] addEventListener (' click ', function () {
Tbody. RemoveChild (enclosing parentNode. ParentNode);
})
}
})
& lt;/script>
& lt;/body>
& lt;/html>
CodePudding user response:
This question is what are you?CodePudding user response:
BTN. AddEventListener (' click ', function () {
If (Dr. Alue!=='& amp; & B.v alue!=='& amp; & C. alue!=='& amp; & D.v alue!=' ') {
Var tr=document. The createElement method (' tr);
Var TRR=tbody. The appendChild (tr);
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=Dr. Alue.
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=b.v alue.
Var td=document. The createElement method (" td ");
The tr. The appendChild (td);
Td. InnerHTML=c. alue.
Var td4=document. The createElement method (" td ");
//td. InnerHTML='& lt; A href="https://bbs.csdn.net/topics/#" & gt; Delete & lt;/a> '
The tr. The appendChild (td4);
Td4. InnerHTML=d.v alue + '& lt; A href="https://bbs.csdn.net/topics/#" & gt; Delete & lt;/a> ';
}
Var aa=td4. GetElementsByTagName (" a ") [0];
Aa. AddEventListener (' click ', function () {
Tbody. RemoveChild (enclosing parentNode. ParentNode);
})
})
CodePudding user response: