Blogger Information
Blog 42
fans 0
comment 0
visits 15336
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0726dom增删改的常用方法,留言板添加自定义样式
小言
Original
263 people have browsed it

dom增删改的常用方法

1.createElement,元素直接在内存中直接渲染并追加到文档中

2.append,可以追加到元素上面所要显示的内容

增加

  1. const ul = document.createElement('ul');
  2. document.body.append(ul);

更改

  1. const li = document.createElement('li');
  2. li.append('new item');
  3. li.style.color = 'red';

3.插入位置,可以在任意元素的开始、中间或做生意地方插入一个子元素,

  1. ul.insertAdjacentHTML('afterbegin' , '<li style=:"color:red">hello</li>');
  2. ul.insertAdjacentHTML('beforeend' , '<li style=:"color:red">hello world</li>');
  3. ul.insertAdjacentHTML('afterend' , '<h4>共计:9个</h4>');

4.remove删除

  1. ul.firstElementChild.remove();
  2. //删掉第一行

留言板自定义样式

利用onkeydown,当按下某个键盘上某个键时去触发这个事件,从而反回值

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!