当前位置:网站首页>节点基础~节点操作
节点基础~节点操作
2022-07-04 07:18:00 【抱抱旋旋子】
一.创建和添加节点
1.创建节点
document.createElement()方法创建由tagName指定的 HTM元素。因为这些元素原先不存在,是根据我们的需求动态生成的,所以我们也称为动态创建元素节点。
2.添加节点
node.appendchild()方法将一个节点添加到指定父节点的子节点列表末尾。类似于css里面的after伪元素。
node.insertBefore ()方法将一个节点添加到父节点的指定子节点前面。类似于css里面的 before伪元素。
简单版发布留言案例
二.删除节点
node. removechild()方法从DOM中删除一个子节点,返回删除的节点。
删除留言
案例分析:
1.当我们把文本域里面的值赋值给li的时候,多添加一个删除的链接
2.需要把所有的链接获取过来,当我们点击当前的链接的时候,删除当前链接所在的li
3.阻止链接跳转需要添加javascriptvoid(0);或者javascript;
三.复制节点
node.cloneaode(方法返回调用该方法的节点的一个副本。也称为克隆节点/拷贝节点
注意:
1.如果括号参数为空或者为false,则是浅拷贝,即只克隆复制节点本身,不克降里面的子节点
2.如果括号参数为true,则是深度拷贝,会复制节点本身以及里面所有的子节点。
边栏推荐
- 关于IDEA如何设置快捷键集
- Electronic Association C language level 1 35, bank interest
- Implementation of ZABBIX agent active mode
- kubernetes集群之Label管理
- Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
- 大厂技术专家:架构设计中常用的思维模型
- Flink memory model, network buffer, memory tuning, troubleshooting
- BibTex中参考文献种类
- A real penetration test
- Industrial computer anti-virus
猜你喜欢
Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
The crackdown on Huawei prompted made in China to join forces to fight back, and another enterprise announced to invest 100 billion in R & D
window上用.bat文件启动项目
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
电脑通过Putty远程连接树莓派
Campus network problems
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
Vulhub vulnerability recurrence 77_ zabbix
手写简易版flexible.js以及源码分析
随机推荐
2022-021ARTS:下半年开始
About how idea sets up shortcut key sets
Technical experts from large factories: common thinking models in architecture design
Centos8 install mysql 7 unable to start up
NLP-文献阅读总结
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
电脑通过Putty远程连接树莓派
云Redis 有什么用? 云redis怎么用?
【Kubernetes系列】Kubernetes 上安装 KubeSphere
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
Selection (023) - what are the three stages of event propagation?
A real penetration test
Summary of MySQL common judgment functions!! Have you used it
Flink memory model, network buffer, memory tuning, troubleshooting
[web security] nodejs prototype chain pollution analysis
Knowledge payment applet dream vending machine V2
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
[Valentine's day] - you can change your love and write down your lover's name
Electronic Association C language level 1 35, bank interest