Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate Random div by Click in js

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces js how to click to generate random div, the article is very detailed, has a certain reference value, interested friends must read it!

Description:

Mouse click on the page, where you click to create a p, width and height 50, random color, p in the middle of the mouse click

Effect:

Achieve:

Js:

Var Method= (function () {return {EVENT_ID: "event_id", loadImage:function (arr) {var img=new Image (); img.arr=arr; img.list= []; img.num=0) / / if the event listening under the DOM object is not deleted, it will reside in the heap / / once the necessary conditions for the event are triggered, the event function img.addEventListener ("load", this.loadHandler); img.self=this; img.src=arr [img.num];}, loadHandler:function (e) {this.list.push (this.cloneNode (false)); this.num++ will continue to be executed. If (this.num > this.arr.length-1) {this.removeEventListener ("load", this.self.loadHandler); var evt=new Event (Method.EVENT_ID); evt.list=this.list; document.dispatchEvent (evt); return;} this.src=this.arr [this.num];}, $c:function (type,parent,style) {var elem=document.createElement (type) If (parent) parent.appendChild (elem); for (var key in style) {elem.style [key] = style [key];} return elem;}, pColor: function () {var col= "#"; / / the format for in which the first bit of this string is # color (var iTuno

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report