最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript封裝彈框插件的方法

 更新時(shí)間:2022年08月23日 11:13:50   作者:可可鴨~??于?2021-11-20?20:32:51?發(fā)布??452  
這篇文章主要為大家詳細(xì)介紹了JavaScript封裝彈框插件的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

JavaScript封裝彈框插件的具體代碼,供大家參考,具體內(nèi)容如下

知識(shí)點(diǎn)1、document.querySelector() 方法

querySelector() 方法返回文檔中匹配指定 CSS 選擇器的一個(gè)元素。
注意: querySelector() 方法僅僅返回匹配指定選擇器的第一個(gè)元素。如果你需要返回所有的元素,請(qǐng)使用 querySelectorAll() 方法替代。
querySelectorAll() 方法返回文檔中匹配指定 CSS 選擇器的所有元素,返回 [NodeList] 對(duì)象。

知識(shí)點(diǎn)2、document.createElement() 用于創(chuàng)建一個(gè)元素

知識(shí)點(diǎn)3、innerHTML可獲取或設(shè)置指定元素標(biāo)簽內(nèi)的 html內(nèi)容,從該元素標(biāo)簽的起始位置到終止位置的全部?jī)?nèi)容(包含html標(biāo)簽)。

<!DOCTYPE html>
<html lang="en">
? <head>
? ? <meta charset="UTF-8" />
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0" />
? ? <meta http-equiv="X-UA-Compatible" content="ie=edge" />
? ? <title>Document</title>
? ? <link rel="stylesheet" href="../css/tanchuang.css" />
? </head>
? <body>
? ? <button>
? ? ? 彈窗
? ? </button>
? ? <script>
? ? ? var control = document.querySelector("button");
? ? ? control.onclick = function() {
? ? ? ? var shade = document.createElement("div");
? ? ? ? shade.className = "shade";
? ? ? ? shade.innerHTML = `
? ? ? ? ? ? <div class="popwindows">
? ? ? ? ? ? <div class="tltle">
? ? ? ? ? ? ? ? <div class="text"><h3>溫馨提示</h3></div>
? ? ? ? ? ? ? ? <div class="exit"></div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="content"><h4>是否添加一個(gè)頁(yè)面生成一個(gè)藍(lán)色div</h4></div>
? ? ? ? ? ? <div class="endbtn">
? ? ? ? ? ? ? ? <div class="btn confirm">確定</div>
? ? ? ? ? ? ? ? <div class="btn cancel">取消</div>
? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? ? `
? ? ? ? ? document.body.appendChild(shade);
? ? ? ? ? var cancel = document.querySelector(".btn.cancel");
? ? ? ? ? cancel.onclick = function() {
? ? ? ? ? document.body.removeChild(shade);
? ? ? ? }
? ? ? ? ? var confirmDiv = document.querySelector(".btn.confirm");
? ? ? ? ? confirmDiv.onclick = function() {
? ? ? ? ? var a = document.createElement("div")
? ? ? ? ? a.style.backgroundColor = "red";
? ? ? ? ? a.style.width = "100px";
? ? ? ? ? a.style.height = "100px";
? ? ? ? ? document.body.appendChild(a);
? ? ? ? ? document.body.removeChild(shade)
? ? ? }
? ? }
? ? </script>
? </body>
</html>

tanchuang.css

* {
? margin: 0;
? padding: 0;
? box-sizing: border-box;
}
.shade {
? display: flex;
? top: 0;
? left: 0;
? width: 100%;
? height: 600px;
? background-color: rgba(0, 0, 0, 0.5);
}
.shade .popwindows {
? width: 400px;
? height: 300px;
? background-color: #f2f2f2;
? position: absolute;
? left: 50%;
? top: 50%;
? transform: translate(-50%, -50%);
? display: flex;
? flex-direction: column;
}
.shade .popwindows .tltle {
? position: relative;
? display: flex;
? flex-direction: row;
? align-items: center;
? width: 100%;
? flex: 1;
? border-bottom: 1px solid #bdb8b8;
}
.shade .popwindows .tltle .text {
? flex: 1;
? float: left;
? padding-left: 10px;
? font-family: "微軟雅黑";
}
.shade .popwindows .tltle .exit {
? width: 30px;
? height: 30px;
? background-image: url("../js學(xué)習(xí)/imag/cuohao.png");
? background-repeat: no-repeat;
? background-position: center center;
? background-size: 20px auto;
? float: right;
? margin-right: 10px;
}
.shade .popwindows .content {
? width: 100%;
? flex: 3;
? line-height: 40px;
? font-size: 13px;
? margin-left: 10px;
? font-family: '宋體';
}
.shade .popwindows .endbtn {
? display: flex;
? justify-content: center;
? align-items: center;
? width: 100%;
? flex: 1;
? border-top: 1px solid #bdb8b8;
}
.shade .popwindows .endbtn .btn{
? ? width: 80px;
? ? text-align: center;
? ? height: 30px;
? ? line-height: 30px;
? ? font-size: 15px;
? ? background-color: #979797;
}
.shade .popwindows .endbtn .btn:nth-child(1){
? ? margin-right: 10px;
}
.shade .popwindows .endbtn .btn:nth-child(2){
? ? margin-right: 10px;
}
.shade .popwindows .endbtn .btn:hover{
? ? background-color: #f68c4e;
}

封裝

<!DOCTYPE html>
<html lang="en">
? <head>
? ? <meta charset="UTF-8" />
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0" />
? ? <meta http-equiv="X-UA-Compatible" content="ie=edge" />
? ? <title>Document</title>
? ? <link rel="stylesheet" href="../css/tanchuang.css" />
? ? <script src="../js文件/popwindows.js"></script>
? </head>
? <body>
? ? <button>添加彈窗</button>
? </body>
? <script>
? ? var button = document.querySelector("button");
? ? button.onclick = function() {
? ? ? var args = {
? ? ? ? title: "嚴(yán)重警告",
? ? ? ? content: "您輸入的內(nèi)容不合法",
? ? ? ? confirmDivfn: function() {
? ? ? ? ? var a = document.createElement("div");
? ? ? ? ? a.style.backgroundColor = "red";
? ? ? ? ? a.style.width = "100px";
? ? ? ? ? a.style.height = "100px";
? ? ? ? ? document.body.appendChild(a);
? ? ? ? },
? ? ? ? cancelfn: function() { ?
? ? ? ? }
? ? ? };
? ? ? Alert(args);
? ? };
? </script>
</html>
/*?
var args = {
title:"溫馨提示",
content:"是否添加一個(gè)頁(yè)面生成一個(gè)藍(lán)色div",
confirmDivfn:function(){
? ? ?var a = document.createElement("div");
? ? ? a.style.backgroundColor = "red";
? ? ? a.style.width = "100px";
? ? ? a.style.height = "100px";
? ? ? body.appendChild(a);
},
cancelfn:function(){
? body.removeChild(shade);
? }
}
*/
function Alert(args) {
? ? var shade = document.createElement("div");
? ? shade.className = "shade";
? ? shade.innerHTML =
? ? ? `
? ? ? ? ? ? <div class="popwindows">
? ? ? ? ? ? <div class="tltle">
? ? ? ? ? ? ? ? <div class="text"><h3>` +
? ? ? args.title +
? ? ? `</h3></div>
? ? ? ? ? ? ? ? <div class="exit"></div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="content"><h4>` +
? ? ? args.content +
? ? ? `</h4></div>
? ? ? ? ? ? <div class="endbtn">
? ? ? ? ? ? ? ? <div class="btn confirm">確定</div>
? ? ? ? ? ? ? ? <div class="btn cancel">取消</div>
? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? ? `;
? ? document.body.appendChild(shade);
? ? var cancel = document.querySelector(".btn.cancel");
? ? var confirmDiv = document.querySelector(".btn.confirm");
? ? confirmDiv.onclick = function() {
? ? ? /* 此處輸入確認(rèn)事件的內(nèi)容*/
? ? ? args.confirmDivfn();
? ? ? document.body.removeChild(shade);
? ? };
? ? cancel.onclick = function() {
? ? ? /* 此處輸入取消事件的內(nèi)容 */
? ? ? args.cancelfn();
? ? ? document.body.removeChild(shade);
? ? };
? };

css不變

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • js data日期初始化的5種方法

    js data日期初始化的5種方法

    本文為大家介紹下js data日期初始化的常用5種方法,感興趣的朋友可以參考下
    2013-12-12
  • JavaScript手寫LRU算法的示例代碼

    JavaScript手寫LRU算法的示例代碼

    LRU是Least?Recently?Used的縮寫,即最近最少使用。作為一種經(jīng)典的緩存策略,它的基本思想是長(zhǎng)期不被使用的數(shù)據(jù),在未來被用到的幾率也不大,所以當(dāng)新的數(shù)據(jù)進(jìn)來時(shí)我們可以優(yōu)先把這些數(shù)據(jù)替換掉。本文用JavaScript實(shí)現(xiàn)這一算法,需要的可以參考一下
    2022-09-09
  • 使用JavaScript?將數(shù)據(jù)網(wǎng)格綁定到?GraphQL?服務(wù)的操作方法

    使用JavaScript?將數(shù)據(jù)網(wǎng)格綁定到?GraphQL?服務(wù)的操作方法

    GraphQL是管理JavaScript應(yīng)用程序中數(shù)據(jù)的優(yōu)秀工具,本教程展示了GraphQL和SpreadJS如何簡(jiǎn)單地構(gòu)建應(yīng)用程序,?GraphQL?和?SpreadJS都有更多功能可供探索,因此您可以做的事情遠(yuǎn)遠(yuǎn)超出了這個(gè)示例,感興趣的朋友一起看看吧
    2023-11-11
  • js 概率計(jì)算(簡(jiǎn)單版)

    js 概率計(jì)算(簡(jiǎn)單版)

    這篇文章主要介紹了js 概率計(jì)算(簡(jiǎn)單版),需要的朋友可以參考下
    2017-09-09
  • OpenLayer學(xué)習(xí)之自定義測(cè)量控件

    OpenLayer學(xué)習(xí)之自定義測(cè)量控件

    這篇文章主要為大家詳細(xì) 介紹了OpenLayer學(xué)習(xí)之自定義測(cè)量控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • 微信小程序canvas動(dòng)態(tài)時(shí)鐘

    微信小程序canvas動(dòng)態(tài)時(shí)鐘

    這篇文章主要為大家詳細(xì)介紹了微信小程序canvas動(dòng)態(tài)時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • bootstrap輸入框組件使用方法詳解

    bootstrap輸入框組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了bootstrap輸入框組件使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • javascript使用輸出語(yǔ)句實(shí)現(xiàn)網(wǎng)頁(yè)特效代碼

    javascript使用輸出語(yǔ)句實(shí)現(xiàn)網(wǎng)頁(yè)特效代碼

    這篇文章主要介紹javascript使用輸出語(yǔ)句實(shí)現(xiàn)網(wǎng)頁(yè)特效,有需要的朋友可以參考下
    2015-08-08
  • eval的兩組性能測(cè)試數(shù)據(jù)

    eval的兩組性能測(cè)試數(shù)據(jù)

    最近對(duì)eval火爆的討論,教主 @Franky 和 灰大 @otakustay 也給了精彩的數(shù)據(jù)分析,剛好之前也做過類似的測(cè)試,我也跟風(fēng)湊個(gè)熱鬧,提供兩組數(shù)據(jù)供大家參考
    2012-08-08
  • 詳解JavaScript閉包的優(yōu)缺點(diǎn)和作用

    詳解JavaScript閉包的優(yōu)缺點(diǎn)和作用

    閉包是指在 JavaScript 中,內(nèi)部函數(shù)可以訪問其外部函數(shù)作用域中的變量,即使外部函數(shù)已經(jīng)執(zhí)行完畢,這種特性被稱為閉包,本文將給大家介紹一下JavaScript閉包的優(yōu)缺點(diǎn)和作用,需要的朋友可以參考下
    2023-09-09

最新評(píng)論

静安区| 南雄市| 福泉市| 绥化市| 平原县| 利川市| 沁水县| 府谷县| 高阳县| 哈尔滨市| 工布江达县| 安阳市| 延边| 个旧市| 洛川县| 麻栗坡县| 阿鲁科尔沁旗| 墨玉县| 昭觉县| 丽江市| 新化县| 余江县| 焉耆| 南和县| 江孜县| 万源市| 德州市| 宁德市| 塔河县| 乌兰县| 东平县| 外汇| 广东省| 黄大仙区| 巫山县| 黄骅市| 乐陵市| 罗江县| 堆龙德庆县| 和田县| 全椒县|