欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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é)號(hào)</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`) //編號(hào)
? ? ? 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(`請(qǐng)輸入姓名`)
? ? ? ? ?return
? ? ? ?}
? ? ? ?if (age.value.trim().length ==0){
? ? ? ? ?alert(`請(qǐng)輸入年齡`)
? ? ? ? ?return
? ? ? ?}
? ? ? ?if (salary.value.trim().length ==0){
? ? ? ? ?alert(`請(qǐng)輸入薪資`)
? ? ? ? ?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=``
? ? ? ? ? ?// 存儲(chǔ)數(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>

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

相關(guān)文章

最新評(píng)論