微博仿写相关

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>微博发布</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      list-style: none;
    }
    .wrap {
      width: 700px;
      margin: 20px auto;
    }
    textarea {
      width: 100%;
      height: 80px;
      border: 1px solid #ccc;
      box-sizing: border-box;
      resize: none;
    }
    .bar {
      margin: 8px 0 20px;
      text-align: right;
    }
    button {
      padding: 4px 16px;
      border: none;
      background: #0088ff;
      color: #fff;
      cursor: pointer;
    }
    button:disabled {
      background: #ccc;
      cursor: not-allowed;
    }
    li {
      padding: 10px 0;
      border-bottom: 1px solid #eee;
      position: relative;
    }
    .del {
      position: absolute;
      right: 0;
      top: 10px;
      cursor: pointer;
      color: red;
    }
  </style>
</head>
<body>
  <div class="wrap">
    <textarea id="inp" maxlength="200" placeholder="输入内容"></textarea>
    <div class="bar">
      <span id="count">0</span>/200
      <button id="send" disabled>发布</button>
    </div>
    <ul id="list"></ul>
  </div>

  <script>
    const inp = document.getElementById('inp');
    const count = document.getElementById('count');
    const send = document.getElementById('send');
    const list = document.getElementById('list');

    inp.oninput = function() {
      let l = this.value.length;
      count.innerText = l;
      send.disabled = l === 0;
    }

    send.onclick = function() {
      let val = inp.value;
      list.innerHTML = `<li>${val}<span class="del">删</span></li>` + list.innerHTML;
      inp.value = '';
      count.innerText = 0;
      send.disabled = true;
    }

    list.onclick = function(e) {
      if (e.target.className === 'del') {
        e.target.parentElement.remove();
      }
    }
  </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值