Blogger Information
Blog 42
fans 0
comment 0
visits 15338
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0727/1.事件冒泡,事件代理2. 字符串API
小言
Original
258 people have browsed it

事件冒泡

根据冒泡的原理,当前元素同名事件,会向上传递到父级,通过一级一级传递来判读当前子元素触发了哪些事件

  1. const ul = document.querySelector('ul');
  2. ul.onclick = function(){
  3. console.log(event.target, event.target.dataset.index);
  4. console.log(event.currentTarget);
  5. console.log(event.target === event.currentTarget);
  6. };

字符串API

1.str.split,该方法把字符串分割成数组

  1. console.log(str.split('', 4));

2.str.toLowerCase 把字符串中的大写转化为小写

  1. let str = 'PHP中文网';
  2. //输出小写
  3. console.log(str.toLowerCase());
  4. //原样输出
  5. console.log(str);

3.str.toUpperCase 把字符串中的小写转化为大写

  1. let str = 'php中文网';
  2. //输出大写
  3. console.log(str.toUpperCase());
  4. //原样输出
  5. console.log(str);

4.去除字符串两端的空白字符

  1. let str = ' php 中文网 ';
  2. //去掉左右空隙
  3. console.log(str.trim());
  4. //原样输出
  5. console.log(str);

5.str.includes 用来判断是否包含指定字符串,包含返回true

  1. console.log(str.includes('php'));

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!