Home > front end >  Ask god to help analyze the delete the problem how to solve, Thanks
Ask god to help analyze the delete the problem how to solve, Thanks

Time:10-13

& lt; ! DOCTYPE html>
& 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:

reference 1st floor weixin_43947294 response:
this question is what are you?

Click the delete button, in the console error, the browser can delete,

CodePudding user response:

The content of the error be sent or tough!

CodePudding user response:

refer to the 4th floor guitar ranch code reply:
error be sent or not make the content of the

Demo. HTML: 86 Uncaught DOMException: Failed to execute 'removeChild' on 'Node, The Node to be removed is not a child of this Node.
The at HTMLAnchorElement. & lt; Anonymous> (file:///F:/%E6%88%91%E7%9A%84%E5%89%8D%E7%AB%AF/%E6%A1%88%E4%BE%8B/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E8%A1%A8/demo.html:86:31)
(anonymous) @ demo. HTML: 86

CodePudding user response:

 
Var aa=document. QuerySelectorAll (' a ');
Aa/aa. The length - 1. The addEventListener (' click ', function () {
Tbody. RemoveChild (enclosing parentNode. ParentNode);
})

Repeat binding events, and triggered an incident, after deleting the elements have been removed again delete will error
So to Singapore this element binding a click event

CodePudding user response:

Demohtml: 86 do not capture DOMException: not on the "Node" perform "removeChild" : to delete the Node is not a child Node of this Node, you have a look at line 86 main problem in 86