Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="content">

        <div class="logo">
          <div><img src="https://imgur.com/LG2pzVL.png" width="400px" alt="">
            
          </div>
          <div class="logotext">華山論劍邀請名單</div>
        </div>
        <div class="addList">
          <input type="text" size="30" class="text" placeholder="請輸入與會者姓名" required>
          <button type="button" class="send">新增邀請名單</button>
        </div>
      
      </div>
      <div class="item">
        <h3>計畫邀請<span class="noneNum"></span>人</h3>
        <ul class="list">
      
        </ul>
      </div>
      <div class="finishedItem">
        <h3>已邀請<span class="doneNum"></span>人</h3>
        <ul id="finishlist">
      
        </ul>
      </div>
              
            
!

CSS

              
                * {
  font-size: 16px;
/*   border: 1px solid; */
  margin-bottom: 10px;
  box-sizing: border-box;
}
body {
  background: #ba010b;
}

.logo {
  color: #2f3033;
  width: 420px;
  margin: 50px auto 30px;
}
.logotext {
  padding-top: 10px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 36px;
  font-weight: 700;
  color: yellow;
  text-align:center;
}
.logo img {
  text-align: center;
  margin-left: 20px;
  margin-right: 20px;
}
.item,
.finishedItem {
  width: 420px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 5px;
  padding-bottom: 15px;
  box-shadow: rgba(198, 198, 231, 0.25) 0px 13px 27px -5px,
    rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;
}
.item {
  margin-top: 50px;
}
.finishedItem {
  margin-top: 50px;
}
.item h3,
.finishedItem h3 {
  text-align: center;
  font-size: 1.1rem;
  margin-top: 5px;
  margin-bottom: 5px;
  color:#fff;
}
.item h3 span,
.finishedItem h3 span {
  padding-left: 15px;
  padding-right: 5px;
  font-size: 1.1rem;
  font-family: Arial, Helvetica, sans-serif;
}
.content {
  margin: 20px auto 0;
  width: 450px;
}
.addList {
  margin: 10px auto 0;
  width: 450px;
  height: 30px;
  /* border: 1px solid; */
  display: flex;
  justify-content: center;
  padding-bottom: 50px;
}
.text {
  padding: 5px 15px;
  background: #fff;
  border: none;
  cursor: pointer;
  -webkit-border-radius: 5px;
  border-radius: 10px;
  outline-style: none;
  font-size: 16px;
  height: 30px;
  color: #3c3c3c;
  cursor: pointer;
}
.send {
  margin-left: 10px;
  height: 30px;
  border-radius: 10px;
  border: none;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 3px;
  background: #f9cd1c;
  color: #0e1012;
  /* line-height: 1; */
}
.list,
#finishlist {
  padding-left: 0px;
  padding-right: 0px;
}
.list li,
#finishlist li {
  list-style-type: none;
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 0.8rem;
  line-height: 1;
}
.list li,
#finishlist li {
  background: rgba(255, 255, 255, .7);
}

.list li a,
#finishlist li a {
  font-size: 0.78rem;
  padding-right: 10px;
}

              
            
!

JS

              
                //指定DOM
let send = document.querySelector('.send');
let list = document.querySelector('.list');
let finishList = document.getElementById('finishlist');

//資料:設定計畫邀請名單「listData」的localStorage資料,轉為陣列物件
let data = JSON.parse(localStorage.getItem('listData')) || [];
//資料:設定寄出名單「listFinish」的localStorage資料,轉為陣列物件
let finishData = JSON.parse(localStorage.getItem('listFinish')) || [];


//事件綁定,監聽與更新
send.addEventListener('click', addData);
list.addEventListener('click', toggleDone);
finishList.addEventListener('click', deleDone);

//更新畫面上的資料
updateList(data);
updateFinish(finishData);

//按下「新增邀請名單後」,把資料新增到data中,並叫用updateList
function addData(e) {
    var txt = document.querySelector('.text');
    if (txt.value == "") {
        alert('必須輸入與會者姓名');
        return;
    }
    var toInvite =
    {
        content: txt.value
    }

    data.push(toInvite);    
    updateList(data);
    localStorage.setItem('listData', JSON.stringify(data));
    txt.value = '';
}
//更新邀請清單
function updateList(items) {
    str = '';
    let len = items.length;    
    for (let i = 0; len > i; i++) {
        console.log(items[i])
        str += `<li><a href="#" data-index=${i}>移到已邀請</a><span>${items[i].content}</span></li>`;
    }
    list.innerHTML = str;
    let noneNum = document.querySelector('.noneNum');
    noneNum.textContent = len;
}

//將與會者由邀請清單移至邀請函已寄出清單
function toggleDone(e){
    e.preventDefault();
    if(e.target.nodeName !== 'A'){
        return;
    }
    let index = e.target.dataset.index;
    console.log(index);
    finishData.push(data[index]);
    console.log(data[index]);
    data.splice(index,1);
    localStorage.setItem('listData',JSON.stringify(data));
    updateList(data);
    localStorage.setItem('listFinish',JSON.stringify(finishData));
    updateFinish(finishData);
}

//更新已寄邀請函清單
function updateFinish(finishItems){
    let mailStr = '';
    let len = finishItems.length;
    console.log(finishItems);
    console.log(len);
    for(let i=0;i<len; i++){
        console.log(finishItems[i]);
        mailStr+= `<li><a href="#" data-num=${i}>移除</a><span>${finishItems[i].content}</span></li>`
    }
    finishList.innerHTML = mailStr;
    var doneNum = document.querySelector('.doneNum');
    doneNum.textContent = len;
}

//刪除已邀請的貴賓
function deleDone(e){
    e.preventDefault();
    if(e.target.nodeName !== 'A'){
        return;
    }
    let num = e.target.num;
    finishData.splice(num,1);
    localStorage.setItem('listFinish',JSON.stringify(finishData));
    updateFinish(finishData);
}


              
            
!
999px

Console