电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

JavaScript實現通訊錄功能

瀏覽:6日期:2023-06-12 09:03:29

本文實例為大家分享了JavaScript實現通訊錄功能的具體代碼,供大家參考,具體內容如下

JavaScript實現通訊錄功能JavaScript實現通訊錄功能JavaScript實現通訊錄功能JavaScript實現通訊錄功能JavaScript實現通訊錄功能

直接貼代碼

index.css

BODY,HTML { width: 100%; height: 100%; margin: 0px; font-family: 'PingFang SC', '微軟雅黑', sans-serif; font-weight: 300; color: #333;}.header { width: 100%; padding: 32px;}h1 { margin: 32px; float: left; font-weight: 300; font-size: 24px;}#add { margin: 32px; margin-top: 38px; float: right; width: 24px;}#tip { width: 100%; text-align: center; position: fixed; top: 240px; color: #9E9E9E;}#mask { position: fixed; width: 100%; height: 100%; background: rgba(33, 33, 33, 0.72); z-index: 999; display: flex; justify-content: center; align-items: center; -webkit-transition: all 500ms; -moz-transition: all 500ms; -o-transition: all 500ms; transition: all 500ms;}#panel { width: 330px; height: 320px; background: #FFF; border-radius: 10px; box-shadow: 0 15px 30px 0 rgba(0, 0, 0, 0.08), 0 4px 8px 0 rgba(0, 0, 0, 0.08); text-align: center; -webkit-transition: all 300ms; -moz-transition: all 300ms; -o-transition: all 300ms; transition: all 300ms;}#avatar { margin: 0px auto; margin-top: -48px; width: 96px; height: 96px; border-radius: 50%; background: #FFF; background-size: cover !important; border: 2px solid #FFFFFF; box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.12); -webkit-transition: all 500ms; -moz-transition: all 500ms; -o-transition: all 500ms; transition: all 500ms;}#random { color: #4A90E2; text-decoration: underline;}input { margin: 0px; width: 60%; background: #FFFFFF; border: 2px solid #EEEEEE; border-radius: 10px; font-size: 16px; padding: 12px 16px; outline: none; -webkit-transition: all 500ms; -moz-transition: all 500ms; -o-transition: all 500ms; transition: all 500ms; margin-top: 8px;}input:first-child { margin-top: 24px;}input:focus { border: 2px solid #4A90E2;}#save { width: 26%; background: #4A90E2; border-radius: 10px; padding: 12px; color: #FFF; margin-top: 24px; float: left; margin-left: 48px;}#cancel { width: 26%; background: #EEEEEE; border-radius: 10px; padding: 12px; color: #333; margin-top: 24px; float: right; margin-right: 48px;}/* 禁用鼠標 */.disableAddModal { background: rgba(33, 33, 33, 0) !important; pointer-events: none;} /* 完全透明 */.disableAddModal #panel { transform: scale(0.9); opacity: 0; }#content { padding: 16px; padding-top: 97px;}.card { margin-top: 8px; width: 100%; height: 104px; background: #FFFFFF; box-shadow: 0 15px 30px 0 rgba(0, 0, 0, 0.08), 0 4px 8px 0 rgba(0, 0, 0, 0.08); border-radius: 10px; overflow: hidden; -webkit-transition: all 300ms; -moz-transition: all 300ms; -o-transition: all 300ms; transition: all 300ms;}.card_expand { height:145px !important;}.card_expand .expand { margin-top: 16px !important;}.avatar { margin-top: 24px; margin-left: 24px; float: left; width: 56px; height: 56px; border-radius: 50%; background: #9E9E9E; background-size: cover !important; border: 2px solid #FFFFFF; border: 3px solid #EEEEEE;}.group { margin-left: 16px; margin-top: 33px; float: left; line-height: 2px;}.info { font-size: 12px; color: #9E9E9E;}.more { padding: 24px; margin-top: 28px; width: 16px; float: right;}.expand { width: 100%; float: left; margin-top: 24px;}.edit { text-align:center; vertical-align:middle; display:flex; align-items: center ; justify-content: center; background: url('./img/edit.png'); background-size: cover; float: left; width: 50%; height: 43px; -webkit-transition: all 200ms; -moz-transition: all 200ms; -o-transition: all 200ms; transition: all 200ms;}.edit:hover { background: url('./img/edit-active.png'); background-size: cover;}.delete { background: url('./img/delete.png'); background-size: cover; float: right; width: 50%; height: 43px; display:flex; align-items: center ; justify-content: center; -webkit-transition: all 200ms; -moz-transition: all 200ms; -o-transition: all 200ms; transition: all 200ms;}.delete:hover { background: url('./img/delete-active.png'); background-size: cover;}.line { float: left; height: 24px; border-right: #EEE 1px solid; margin-left: -1px; margin-top: 8px;}

index.html

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>App</title> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <link rel='stylesheet' href='http://www.hdgsjgj.cn/bcjs/index.css'></head><body> <div class='disableAddModal'> <div id='panel'> <div id='avatar'></div> <p id='random'>隨機頭像</p> <input type='text' placeholder='請輸入中文姓名'> <input type='text' placeholder='請輸入英文姓名'> <div id='save'>保存</div> <div id='cancel'>取消</div> </div> </div> <div id='header'> <h1 id='title'>通信錄</h1> <img src='http://www.hdgsjgj.cn/bcjs/img/add.png' alt='' /> </div> <p id='tip'> 當前沒有任何聯系人<br /> 請點擊右上角添加 </p> <div id='content'> <div style='display:none;'> <div class='avatar'></div> <div class='group'> <p class='name'>測試</p> <p class='info'>Test</p> </div> <img src='http://www.hdgsjgj.cn/bcjs/img/more.png' alt='' class=' more'> <div > <div >修改</div> <div class='line'></div> <div class='delete'>刪除</div> </div> </div> </div> <script src='http://www.hdgsjgj.cn/bcjs/index.js'></script></body></html>

index.js

// 獲取所需要的dom元素var DOM = { mask: document.getElementById(’mask’), add: document.getElementById(’add’), avatar: document.getElementById(’avatar’), names: document.getElementById(’name’), infos: document.getElementById(’info’), save: document.getElementById(’save’), cancel: document.getElementById(’cancel’), random: document.getElementById(’random’), content: document.getElementById(’content’), template: document.getElementById(’template’), tip: document.getElementById(’tip’),};// 隨機生成名稱和英文名data = [ { name: ’佐藤’, info: ’さとう’ }, { name: ’鈴木’, info: ’すずき’ }, { name: ’高橋’, info: ’たかはし’ }, { name: ’田中’, info: ’たなか’ }, { name: ’高橋’, info: ’たかはし’ }, { name: ’渡邊’, info: ’わたなべ’ }, { name: ’伊藤’, info: ’いとう’ }, { name: ’小林’, info: ’こばやし’ }, { name: ’山本’, info: ’やまもと’ },];var nowNode;// 彈出框function disableAddModal(show) { switch (show) { case true: // mask 的class名稱修改為 空 顯示添加框 DOM.mask.className = ’’; // 隨機頭像 DOM.avatar.style.backgroundImage = 'url(’./avatar/' + Math.floor(Math.random() * 47) + '.jpg’)'; // 隨機數賦予變量 index = Math.floor(Math.random() * data.length); // 字典內隨機取值 DOM.names.value = data[index].name; DOM.infos.value = data[index].info; break; case false: // 隱藏添加框 DOM.mask.className = ’disableAddModal’; break; default: break; }}// 添加DOM.add.addEventListener(’click’, function () { disableAddModal(true);});// 關閉DOM.cancel.addEventListener(’click’, function () { nowNode = undefined; disableAddModal(false);});// 隨機頭像生成DOM.random.addEventListener(’click’, function () { DOM.avatar.style.backgroundImage = 'url(’./avatar/' + Math.floor(Math.random() * 47) + '.jpg’)';});// 擴展選項function expand(params) { // var that = params.parentNode.className; // 未顯示 if (params.parentNode.className == ’card card_expand’) { params.parentNode.className = ’card ’; } else { //顯示中 params.parentNode.className = ’card card_expand’; }}// 修改function edit(params) { // 將本元素賦值 nowNode = params; // 顯示彈窗 disableAddModal(true); // DOM.avatar.style.background = params.getElementsByClassName(’avatar’)[0].style.background; //將現用的頭像、名稱、英文名 賦值給彈窗 DOM.avatar.style.backgroundImage = nowNode.getElementsByClassName( ’avatar’ )[0].style.backgroundImage; DOM.names.value = nowNode.getElementsByClassName(’name’)[0].innerText; DOM.infos.value = nowNode.getElementsByClassName(’info’)[0].innerText;}//刪除function remove(params) { params.remove();}//保存DOM.save.addEventListener(’click’, function () { var node; DOM.tip.style.display = ’none’; // 是否為undifind // !!noDode 為nowNode 不為空 if (!!nowNode) { // console.log(’nowNode不為空:’ + nowNode); node = nowNode; } else { //復制DOM.template 元素 node = DOM.template.cloneNode(true); // console.log(’nowNode為空:’+node) } // node = DOM.template.cloneNode(true); node.style.display = ’block’; node.getElementsByClassName(’name’)[0].innerText = DOM.names.value; node.getElementsByClassName(’info’)[0].innerText = DOM.infos.value; node.getElementsByClassName(’avatar’)[0].style.backgroundImage = DOM.avatar.style.backgroundImage; node.getElementsByClassName(’more’)[0].addEventListener(’click’, function () { // console.log(this); expand(this); }); node.getElementsByClassName(’edit’)[0].addEventListener(’click’, function () { // console.log(this.parentNode.parentNode); edit(this.parentNode.parentNode); // console.log(’nowNode’ + nowNode); }); node.getElementsByClassName(’delete’)[0].addEventListener(’click’, function () { // console.log(this.parentNode.parentNode); remove(this.parentNode.parentNode); // console.log(’nowNode’ + nowNode); }); // 如果不存在會創建新的,如果存在會替換 DOM.content.appendChild(node); nowNode = undefined; disableAddModal(false);});

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 冷轧机|两肋冷轧机|扁钢冷轧机|倒立式拉丝机|钢筋拔丝机|收线机-巩义市华瑞重工机械制造有限公司 | 【中联邦】增稠剂_增稠粉_水性增稠剂_涂料增稠剂_工业增稠剂生产厂家 | 包头市鑫枫装饰有限公司| 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 学叉车培训|叉车证报名|叉车查询|叉车证怎么考-工程机械培训网 | 脱硫搅拌器厂家-淄博友胜不锈钢搅拌器厂家 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 冷轧机|两肋冷轧机|扁钢冷轧机|倒立式拉丝机|钢筋拔丝机|收线机-巩义市华瑞重工机械制造有限公司 | 体坛网_体坛+_体坛周报新闻客户端| 成都离婚律师|成都结婚律师|成都离婚财产分割律师|成都律师-成都离婚律师网 | 天津电机维修|水泵维修-天津晟佳机电设备有限公司 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 北京京云律师事务所| 包装盒厂家_纸盒印刷_礼品盒定制-济南恒印包装有限公司 | 电子元器件呆滞料_元器件临期库存清仓尾料_尾料优选现货采购处理交易商城 | 立式硫化罐-劳保用品硫化罐-厂家直销-山东鑫泰鑫硫化罐厂家 | 广州展览制作工厂—[优简]直营展台制作工厂_展会搭建资质齐全 | 线材成型机,线材折弯机,线材成型机厂家,贝朗自动化设备有限公司1 | 安全阀_弹簧式安全阀_美标安全阀_工业冷冻安全阀厂家-中国·阿司米阀门有限公司 | 明渠式紫外线杀菌器-紫外线消毒器厂家-定州市优威环保 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 厌氧反应器,IC厌氧反应器,厌氧三相分离器-山东创博环保科技有限公司 | 不锈钢复合板|钛复合板|金属复合板|南钢集团安徽金元素复合材料有限公司-官网 | 非小号行情 - 专业的区块链、数字藏品行情APP、金色财经官网 | 电磁流量计_智能防腐防爆管道式计量表-金湖凯铭仪表有限公司 | led冷热冲击试验箱_LED高低温冲击试验箱_老化试验箱-爱佩百科 | 天津暖气片厂家_钢制散热器_天津铜铝复合暖气片_维尼罗散热器 | 清水混凝土修复_混凝土色差修复剂_混凝土色差调整剂_清水混凝土色差修复_河南天工 | sfp光模块,高速万兆光模块工厂-性价比更高的光纤模块制造商-武汉恒泰通 | 中医治疗皮肤病_潍坊银康医院「山东」重症皮肤病救治平台 | LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | 曙光腾达官网-天津脚手架租赁-木板架出租-移动门式脚手架租赁「免费搭设」 | 环压强度试验机-拉链拉力试验机-上海倾技仪器仪表科技有限公司 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 |