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

JavaScript封裝彈框插件的方法

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

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

知識點1、document.querySelector() 方法

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

知識點2、document.createElement() 用于創(chuàng)建一個元素

知識點3、innerHTML可獲取或設(shè)置指定元素標(biāo)簽內(nèi)的 html內(nèi)容,從該元素標(biāo)簽的起始位置到終止位置的全部內(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>是否添加一個頁面生成一個藍色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: "嚴重警告",
? ? ? ? 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:"是否添加一個頁面生成一個藍色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() {
? ? ? /* 此處輸入確認事件的內(nèi)容*/
? ? ? args.confirmDivfn();
? ? ? document.body.removeChild(shade);
? ? };
? ? cancel.onclick = function() {
? ? ? /* 此處輸入取消事件的內(nèi)容 */
? ? ? args.cancelfn();
? ? ? document.body.removeChild(shade);
? ? };
? };

css不變

以上就是本文的全部內(nèi)容,希望對大家的學(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)典的緩存策略,它的基本思想是長期不被使用的數(shù)據(jù),在未來被用到的幾率也不大,所以當(dāng)新的數(shù)據(jù)進來時我們可以優(yōu)先把這些數(shù)據(jù)替換掉。本文用JavaScript實現(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如何簡單地構(gòu)建應(yīng)用程序,?GraphQL?和?SpreadJS都有更多功能可供探索,因此您可以做的事情遠遠超出了這個示例,感興趣的朋友一起看看吧
    2023-11-11
  • js 概率計算(簡單版)

    js 概率計算(簡單版)

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

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

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

    微信小程序canvas動態(tài)時鐘

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

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

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

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

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

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

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

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

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

最新評論

永平县| 石泉县| 霍林郭勒市| 兰溪市| 广东省| 忻州市| 冀州市| 哈巴河县| 庆安县| 水富县| 永定县| 吐鲁番市| 溧阳市| 英吉沙县| 新密市| 永和县| 汕头市| 阿图什市| 临夏市| 潢川县| 裕民县| 彰化市| 白城市| 资阳市| 鄂托克前旗| 阳高县| 荥经县| 玉溪市| 广东省| 合肥市| 襄汾县| 凤山市| 腾冲县| 汤原县| 长宁区| 卢湾区| 肥城市| 苍溪县| 收藏| 舞阳县| 枣阳市|