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

JS實(shí)現(xiàn)用戶管理系統(tǒng)

 更新時(shí)間:2022年08月25日 16:45:14   作者:歐歐呀  
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)用戶管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JS實(shí)現(xiàn)用戶管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:

html代碼:  

<h1>新增學(xué)員</h1>
? ? <div class="info">
? ? ? 姓名:<input type="text" class="uname" />
? ? ? ?年齡:<input type="text" class="age" />
? ? ? 性別:
? ? ? <select name="gender" id="" class="gender">
? ? ? ? <option value="男">男</option>
? ? ? ? <option value="女">女</option>
? ? ? </select>
? ? ? 薪資:<input type="text" class="salary" /> 就業(yè)城市:<select
? ? ? ? name="city"
? ? ? ? id=""
? ? ? ? class="city"
? ? ? >
? ? ? ? <option value="北京">北京</option>
? ? ? ? <option value="上海">上海</option>
? ? ? ? <option value="廣州">廣州</option>
? ? ? ? <option value="深圳">深圳</option>
? ? ? ? <option value="曹縣">曹縣</option>
? ? ? </select>
? ? ? <button class="add">錄入</button>
? ? </div>
?
? ? <h1>就業(yè)榜</h1>
? ? <table>
? ? ? <thead>
? ? ? ? <tr>
? ? ? ? ? <th>學(xué)號</th>
? ? ? ? ? <th>姓名</th>
? ? ? ? ? <th>年齡</th>
? ? ? ? ? <th>性別</th>
? ? ? ? ? <th>薪資</th>
? ? ? ? ? <th>就業(yè)城市</th>
? ? ? ? ? <th>操作</th>
? ? ? ? </tr>
? ? ? </thead>

css代碼:

* {
? margin: 0;
? padding: 0;
}
?
a {
? text-decoration: none;
? color:#721c24;
}
h1 {
? text-align: center;
? color:#333;
? margin: 20px 0;
?
}
table {
? margin:0 auto;
? width: 800px;
? border-collapse: collapse;
? color:#004085;
}
th {
? padding: 10px;
? background: #cfe5ff;
??
? font-size: 20px;
? font-weight: 400;
}
td,th {
? border:1px solid #b8daff;
}
td {
? padding:10px;
? color:#666;
? text-align: center;
? font-size: 16px;
}
tbody tr {
? background: #fff;
}
tbody tr:hover {
? background: #e1ecf8;
}
.info {
? width: 900px;
? margin: 50px auto;
? text-align: center;
}
.info ?input {
? width: 80px;
? height: 25px;
? outline: none;
? border-radius: 5px;
? border:1px solid #b8daff;
? padding-left: 5px;
}
.info button {
? width: 60px;
? height: 25px;
? background-color: #004085;
? outline: none;
? border: 0;
? color: #fff;
? cursor: pointer;
? border-radius: 5px;
}
.info .age {
? width: 50px;
}

JS代碼:

<script>
? ? ? // 獲取元素
? ? ? let tbody=document.querySelector(`tbody`)
? ? ? // 錄入按鈕
? ? ? let add = document.querySelector(`.add`)
? ? ? let stuId=document.querySelector(`.stuId`) //編號
? ? ? let uname=document.querySelector(`.uname`) //姓名
? ? ? let age=document.querySelector(`.age`) //年齡
? ? ? let gender=document.querySelector(`.gender`) //性別
? ? ? let salary=document.querySelector(`.salary`)//薪資
? ? ? let city=document.querySelector(`.city`) //所在地區(qū)
? ? ? // 刪除按鈕
? ? ? let del = document.querySelector(`.del`)
?
? ? ? // ?保存數(shù)據(jù)
? ? ? let arr = JSON.parse(localStorage.getItem(`key`)) || []
?
? ? ? // ?函數(shù)封裝
? ? ? ? function init(){
? ? ? ? ? // ?創(chuàng)建一個(gè)變量,用于拼接
? ? ? ? let htmlStr=``
? ? ? ? // ?循環(huán)遍歷
? ? ? ? for(let i=0;i<arr.length;i++){
? ? ? ? ? let index= i+1
? ? ? ? ? // 拼接
? ? ? ? ? htmlStr +=` ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${index}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${arr[i].uname}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${arr[i].age}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${arr[i].gender}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${arr[i].salary}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>${arr[i].city}</td>
? ? ? ? ? ? ? ? ? ? ? ? ?<td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<a href="javascript:" class="del" id='${index}''>刪除</a>?
? ? ? ? ? ? ? ? ? ? ? ? ?</td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? ?`
? ? ? ? }
? ? ? ? // 將拼接的元素插入tbody
? ? ? ? tbody.innerHTML=htmlStr
? ? ? ? }
? ? ? ? // 調(diào)用函數(shù)
? ? ? ? init()
?
?
? ? ? ? // 給錄入按鈕添加點(diǎn)擊事件
? ? ? add.addEventListener(`click`,function(){
? ? ? ? // 判斷輸入框是否為空
? ? ? ? if (uname.value.trim().length ==0){
? ? ? ? ?alert(`請輸入姓名`)
? ? ? ? ?return
? ? ? ?}
? ? ? ?if (age.value.trim().length ==0){
? ? ? ? ?alert(`請輸入年齡`)
? ? ? ? ?return
? ? ? ?}
? ? ? ?if (salary.value.trim().length ==0){
? ? ? ? ?alert(`請輸入薪資`)
? ? ? ? ?return
? ? ? ?}
? ? ? ? let obj={
? ? ? ? ? //獲取表單元素的value值,
? ? ? ? ? Id:arr.length>0?arr[arr.length-1].stuId+1 :1001,
? ? ? ? ? uname:uname.value,
? ? ? ? ? age:age.value,
? ? ? ? ? gender:gender.value,
? ? ? ? ? salary:salary.value,
? ? ? ? ? city:city.value,
? ? ? ? }
? ? ? ? ? ?// ?將obj追加到數(shù)組的最后
? ? ? ? ? ?arr.push(obj)
? ? ? ? ? ?// 渲染
? ? ? ? ? ? ? ?init()
?
? ? ? ? ? // 每次錄入清空輸入框
? ? ? ? ? uname.value=``
? ? ? ? ? age.value=``
? ? ? ? ? salary.value=``
? ? ? ? ? ?// 存儲數(shù)據(jù)
? ? ? ? ? localStorage.setItem(`key`,JSON.stringify(arr))
? ? ? })
? ? ? // 實(shí)現(xiàn)數(shù)據(jù)刪除
? ? ? // 給tbody點(diǎn)擊事件,事件委托
? ? ? tbody.addEventListener(`click`,function(e){
? ? ? ? // 獲取刪除按鈕
? ? ? ? if (e.target.className ==`del`){
? ? ? ? ? // 指定刪除arr數(shù)組
? ? ? ? ? arr.splice(e.target.id-1,1)
? ? ? ? ? // 調(diào)用函數(shù)
? ? ? ? ? init()
? ? ? ? }
? ? ? ? localStorage.setItem(`key`,JSON.stringify(arr))
? ? ? ??
? ? ? })
</script>

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

相關(guān)文章

  • Bootstrap的class樣式小結(jié)

    Bootstrap的class樣式小結(jié)

    本文給大家總結(jié)了bootstrap的class樣式,由基礎(chǔ)到內(nèi)涵給大家介紹的非常詳細(xì),需要的的朋友可以參考下
    2016-12-12
  • innerText和textContent對比及使用介紹

    innerText和textContent對比及使用介紹

    innerText使用過程中遇到了FireFox的兼容問題FireFox不支持innerText方法但是有個(gè)類似的方法,叫textContent,類似innerText,都是用來獲?。ㄔO(shè)置)元素中text的方法,感興趣的朋友可以參考下
    2013-02-02
  • 微信小程序web-view不支持打開非業(yè)務(wù)域名https?//XXXX?請重新配置的解決辦法

    微信小程序web-view不支持打開非業(yè)務(wù)域名https?//XXXX?請重新配置的解決辦法

    小程序現(xiàn)在日漸成熟,功能也越來越強(qiáng)大,我們今天來一起看看小程序跳轉(zhuǎn)H5頁面的問題,下面這篇文章主要給大家介紹了關(guān)于微信小程序web-view不支持打開非業(yè)務(wù)域名https?//XXXX?請重新配置的解決辦法,需要的朋友可以參考下
    2022-08-08
  • js中用事實(shí)證明cssText性能高的問題

    js中用事實(shí)證明cssText性能高的問題

    首先要感謝 EtherDream 的不同觀點(diǎn),在 巧用cssText屬性批量操作樣式 一篇中由于他的質(zhì)疑態(tài)度使我做了進(jìn)一步的測試。
    2011-03-03
  • JavaScript改變this指向的四種方法(bind、call、apply 和箭頭函數(shù))

    JavaScript改變this指向的四種方法(bind、call、apply 和箭頭函數(shù))

    JavaScript中的this是一個(gè)非常重要且容易困惑的概念,主要用于引用執(zhí)行上下文,然而,this的指向經(jīng)常因?yàn)椴煌膱?zhí)行環(huán)境而改變,為了解決這個(gè)問題,JavaScript提供了多種方法來明確指定this的指向,本文將詳細(xì)介紹JavaScript中常用的四種改變this指向的方法
    2025-03-03
  • JavaScript中reduce方法的用法及使用場景

    JavaScript中reduce方法的用法及使用場景

    reduce()方法對數(shù)組中的每個(gè)元素按序執(zhí)行一個(gè)提供的reducer函數(shù),每一次運(yùn)行 reducer會將先前元素的計(jì)算結(jié)果作為參數(shù)傳入,最后將其結(jié)果匯總為單個(gè)返回值,今天我們就介紹一下reduce的幾種簡單使用場景,需要的朋友可以參考下
    2023-08-08
  • 向fckeditor編輯器插入指定代碼的方法

    向fckeditor編輯器插入指定代碼的方法

    這篇文章主要向大家分享如何在fckeditor編輯器插入代碼操作,這里腳本之家小編就為大家分享一下啊
    2007-05-05
  • 一文了解TypeScript數(shù)據(jù)類型

    一文了解TypeScript數(shù)據(jù)類型

    本文主要介紹了TypeScript數(shù)據(jù)類型,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-07-07
  • 淺談JS中逗號運(yùn)算符的用法

    淺談JS中逗號運(yùn)算符的用法

    下面小編就為大家?guī)硪黄獪\談JS中逗號運(yùn)算符的用法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • layui table 列寬百分比顯示的實(shí)現(xiàn)方法

    layui table 列寬百分比顯示的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇layui table 列寬百分比顯示的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09

最新評論

遂川县| 宝兴县| 长武县| 海晏县| 陆川县| 隆回县| 宁乡县| 遵义市| 遂溪县| 涟水县| 甘谷县| 诸城市| 安宁市| 邓州市| 类乌齐县| 桃园县| 齐齐哈尔市| 格尔木市| 张家川| 江永县| 天台县| 和顺县| 丹凤县| 贵德县| 沂源县| 建德市| 牡丹江市| 子长县| 长汀县| 台北县| 桃源县| 松江区| 琼结县| 博野县| 蓬莱市| 泸州市| 馆陶县| 通许县| 焉耆| 台北市| 德兴市|