h5 api

作者: 我是好同学 | 来源:发表于2019-10-28 18:47 被阅读0次

api

1.element.outerHTML

返回内容包含描述元素(element)及其后代的 html 代码片段

var div = document.createElement('div');
div.className = 'box box1'
console.log(div.outerHTML);//<div class="box box1"></div>
2.element.classList的方法

只读属性。返回一个元素类属性的DOMTokenList集合。

**DOMTokenList** 接口表示一组空格分隔的标记(tokens)。有length属性,表述存储的个数

1.add ( String )

添加类

var div = document.createElement('div');
div.className = 'box box1';

console.log(div.outerHTML);//<div class="box box1"></div>

//添加一个类
div.classList.add('box2')
console.log(div.outerHTML)//<div class="box box1 box2"></div>

//添加多个类
div.classList.add('box3','box4')
console.log(div.outerHTML)//<div class="box box1 box2 box3 box4"></div>
2.remove ( String )

移除类

//移除一个类
div.classList.remove('box2')
console.log(div.outerHTML)//<div class="box box1 box3 box4"></div>

//移除多个类
div.classList.remove('box3','box4')
console.log(div.outerHTML)//<div class="box box1"></div>
3.item ( Number )

返回指定序列的类

//返回指定序列的类
console.log(div.classList)//DOMTokenList [ "box", "box1" ]
console.log(div.classList.length)//2
console.log(div.classList.item(0))//box
console.log(div.classList.item(1))//box1
4.toggle ( String )

切换某个类。不存在添加,存在删除

//toggle
div.classList.toggle('box333')
console.log(div.outerHTML)//<div class="box box1 box333"></div>
div.classList.toggle('box333')
console.log(div.outerHTML)//<div class="box box1"></div>
div.classList.toggle('box333')
console.log(div.outerHTML)//<div class="box box1 box333"></div>
div.classList.toggle('box333')
console.log(div.outerHTML)//<div class="box box1"></div>
5. contains ( String )

判断是否包含某个类.返回布尔值

//contains
console.log(div.classList.contains('box'))//true
console.log(div.classList.contains('box444'))//false
6.replace ( oldClass,newClass )

替换某个类

//replace
var cls = ['box','bar'];
//替换前
console.log(div.outerHTML)//<div class="box box1"></div>
//用类名bar替换box
div.classList.replace(...cls);
console.log(div.outerHTML)//<div class="bar box1"></div>

更多 h5 api 查看

相关文章

  • 手机H5获取地理位置

    手机H5想要获取地理位置需要的工具,或者API: 百度地址api 手机H5获取地理位置,直接上代码, [获取授权]

  • js实现页面全屏和元素全屏

    全屏API H5有一个全屏API,Element.requestFullscreen() 方法用于发出异步请求使元...

  • vue H5 与 原生交互

    H5调原生 api.js /** * @name 判断iOS */ export const isiOS = ()...

  • H5 : web storage api

    web storage api:web-storage是一些关于web存储的api集. H5的web storag...

  • Number three

    Canvas 基础篇 1.它是H5新的API 什么是API ? 答:接口 广义上的意义 2.can...

  • vue+七牛云上传视频文件

    Qiniu-JavaScript-SDK基于七牛云存储官方 API 构建,其中上传功能基于 H5 File API...

  • 利用performance统计网站的加载新能

    介绍利用H5 api接口performance,统计网站的加载时间,进而优化加载速度。在做H5项目的时候,首屏加载...

  • h5 api

    api 1.element.outerHTML 返回内容包含描述元素(element)及其后代的 html 代码片...

  • H5 API

    地理位置(Geolocation)是 HTML5 的重要特性之一,提供了确定用户位置的功能,借助这个特性能够开发基...

  • 分享 ‖ 星空访谈录

    http://v2api.cdrb.com.cn/h5/?from=timeline#/detail/paper/...

网友评论

      本文标题:h5 api

      本文链接:https://www.haomeiwen.com/subject/uvzbvctx.html