亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JavaScript實(shí)現(xiàn)網(wǎng)頁留言板功能

 更新時(shí)間:2020年11月23日 09:18:57   作者:我是Dreamer啊  
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁留言板功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

JavaScript(JS)網(wǎng)頁–留言板,供大家參考,具體內(nèi)容如下

在使用網(wǎng)頁進(jìn)行沖浪時(shí),經(jīng)常會(huì)發(fā)表自己的留言。發(fā)布留言的留言板是怎么做的呢?

制作一個(gè)簡(jiǎn)單的留言板。

首先需要一個(gè)textarea框,旁邊放置一個(gè)按鈕,然后需要一個(gè)ul標(biāo)簽,里面不需要放置li元素,用CSS加以簡(jiǎn)單的修飾。

緊接著獲取元素,在點(diǎn)擊按鈕后,創(chuàng)建一個(gè)li,將文本框里面的賦值給li,將li插入到ul的第一個(gè)孩子的前面。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>留言發(fā)布</title>
  <style>
    body {
      margin: 200px;
    }
    *{
      margin: 0px;
      padding: 0px;
    }
    li {
      list-style: none;
      width: 500px;
      height: 30px;
      margin-top: 5px;
      border: 1px solid black;
      background-color: pink;
    }
    textarea{
      width: 200px;
      height: 80px;
    } 
  </style>
</head>
<body>
  <textarea name="" id=""></textarea>
  <button>發(fā)布</button>
  <ul>
    
  </ul>
  <script>
    //獲取元素
    var btn = document.querySelector('button');
    var text = document.querySelector('textarea');
    var ul = document.querySelector('ul');
    //注冊(cè)時(shí)間
    btn.onclick = function(){
      if(text.value == ''){
        alert("您沒有輸入內(nèi)容。")
        return false;
      }else{
        var li = document.createElement('li');
        li.innerHTML = text.value;
        //ul.appendChild(li);
        ul.insertBefore(li,ul.children[0])
      }
      text.value='';
      
    }
  </script>
</body>
</html>

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

相關(guān)文章

最新評(píng)論