Web-API-day4 DOM节点

一、日期对象

1.实例化日期对象

const date = new Date()

指定时间 const date1 = new Date('2025-7-9 22-00-00')

获取日期的另一种表达方式:toLocaleString()

2.获取日期对象每一个部分

getFullYear():获取年份

getMonth()+1:获取月份

getDate():获取月份某中某一天

getHours():获取小时

getMinutes():获取分钟

getSeconds():获取秒数

3.补0函数的制作

将小于10的数值连上一个字符串的0

二、节点

1.查找节点

父级:parentNode

子集:children

兄弟:nextElementSibling、previousElementSibling

2、增加节点

创建新节点:document.createElement('标签名称')

追加节点:parent.appendChild(child)

parent.insertBefore(child,refChild)  // insertBefore(插入的元素, 放到哪个元素的前面)

追加的节点可以是新创建的也可以是页面上已经存在(移动)

克隆节点:元素.cloneNode(true)


  
  • 1
  • 2
  • 3

删除节点:父元素.removeChlid(子元素)

parent.removeChild(child)

三、M端事件

1.touchstart:触摸

2.touchend:离开

3.touchmove:滑动中

 

四、插件

插件: 就是别人写好的一些代码,我们只需要复制对应的代码,就可以直接实现对应的效果
学习插件的基本过程
熟悉官网,了解这个插件可以完成什么需求 https://www.swiper.com.cn/
看在线演示,找到符合自己需求的demo https://www.swiper.com.cn/demo/index.html
查看基本使用流程 https://www.swiper.com.cn/usage/index.html
查看APi文档,去配置自己的插件 https://www.swiper.com.cn/api/index.html
注意: 多个swiper同时使用的时候, 类名需要注意区分

你可能感兴趣的:(javascript,开发语言,ecmascript)