关键词搜索

源码搜索 ×
×

原生js创建并删除dom

发布2020-08-07浏览2049次

详情内容

一言不合上代码,以canvas为例:

id = "canvas1";

//创建一个canvas
var canvas = document.createElement("canvas");
canvas.id = id; 
canvas.width = window.screen.availWidth; 
canvas.height= window.screen.availHeight;
canvas.style.cssText = "position: absolute; left: 0px; top: 0px;pointer-events: none;";

document.body.appendChild(canvas); 

var ctx = canvas.getContext("https://cdn.jxasp.com:9143/image/2d");

//删除它
var self = document.getElementById(id);
var parent = self.parentElement;
parent.removeChild(self);
//document.body.removeChld(self) 应该也可以
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

有关删除一个dom,原生js的例子,网络上充斥着一大抄:

var list=document.getElementById("myList");
list.removeChild(list.childNodes[0]);
  • 1
  • 2

这种例子有什么意义?

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载