In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to use JavaScript singleton mode to achieve custom pop-up box", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to use JavaScript singleton mode to achieve custom pop-up box" this article.
Function
Custom pop-up box title
Custom pop-up box content
Callback function when custom pop-up box is confirmed and closed
Complete code const Dialog = (function () {class Dialog {constructor () {this.ele = document.createElement ('div') this.ele.className =' dialog' document.body.appendChild (this.ele) this.callback = null this.setEvent ()} setContent ({text, topicText, confirmText) CancelText} = options) {this.le [XSS _ clean] = null const top = document.createElement ('div') top.className =' top' const topic = document.createElement ('span') topic.className =' topic' topic [XSS _ clean] = topicText const close = document.createElement ('span') close.className =' close' close [XSS _ clean] ='× 'top.appendChild (topic) top.appendChild (close) const middle = document.createElement ('div') middle.className =' middle' const content = document.createElement ('div') content.className =' content' content [XSS _ clean] = text middle.appendChild (content) const bottom = document.createElement ('div') bottom.className =' bottom' const confirm = document.createElement ('button') confirm.className =' confirm' account [XSS _ clean] = confirmText Const cancel = document.createElement ('button') cancel.className =' cancel' cancel [XSS _ clean] = cancelText bottom.appendChild (confirm) bottom.appendChild (cancel) const wrap = document.createElement ('div') this.ele.appendChild (top) this.ele.appendChild (middle) this.ele.appendChild (bottom) this.ele.style.display =' block'} setEvent () {this.ele.addEventListener ('click') E = > {e = e | | window.event const target = e.target | | e.srcElement if (target.className = 'close') {this.ele.style.display =' none' console.log ('close')} if (target.className =' confirm') {this.ele.style.display = 'none' this.callback (true)} If (target.className = = 'cancel') {this.ele.style.display =' none' this.callback (false)} let instance = null return function (options) Cb) {if (! instance) instance = new Dialog () instance.setContent (options) instance.callback = cb | | function () {} return instance}}) () const dialog = new Dialog ({text: 'prompt text', topicText: 'title', confirmText:'OK', cancelText: 'cancel'}, res = > {console.log (res)})
Effect picture
The above is all the contents of the article "how to use the JavaScript singleton pattern to implement a custom pop-up box". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.