简单实现留言板功能,清除留言框

原创2018-11-14 23:49:24189
摘要:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{padding: 0px;marg

111.png

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Document</title>
 <style type="text/css">
 *{padding: 0px;margin: 0px;}
 body{font-size: 12px}
 .box{width: 600px;height: 500px;border: 1px solid #ccc;margin: 0px auto;padding: 10px}
  img{float: left;width: 150px;height: 24px;}
  .box1{float: left;margin-left: 255px;width: 150px;height: 24px;text-align: right;font-size: 14px;color: #888;}
  .box1 span{font-size: 14px;font-weight: bold;}
  #text{width: 600px;height: 100px;border: 1px solid #888;margin-top: 5px;}
  .box #sp4,#sp1,#sp2,#sp3{float: left;width 30px;height: 30px;line-height: 32px;padding-left: 30px}
  #sp4{margin-left:300px;margin-right: 15px;color: #ccc;}
  #text1{display: inline-block;width: 600px;height: 100px;border: none;margin-bottom: 5px;}
  .box2{width: 600px;border: none;}
  #but{float: right;width: 88px;height: 30px;border: none;background: #ffc09f;color: #fff;}
  </style>
<script type="text/javascript">
    var text,number,leng,but,val1,text1,val2;
    window.onload=function(){
      text=document.getElementById("text");
      text1=document.getElementById("text1");
      number=document.getElementById("number");
      but=document.getElementById("but");
      text.onkeyup=function aa(){
        //获取输入框的字体长度
        val1=text.value.toString();
        leng=140-text.value.length;
        if(leng<0){
          number.style.color="red";
        }else{
          number.style.color="#000";
        }
        //显示长度
        number.innerHTML=leng;
      };
      but.onclick=function bb(){
        if(leng==140){
          alert("你还未曾输入");
          //放回输入框
          text.focus;
        }else if(leng<0){
          alert("你超过了输入框的最大输入字数");
           //放回输入框
          text.focus;
        }else{
         alert("输入成功!!");
        text1.innerHTML=val1;
        val2=text.Value="";
        leng=140;
        number.innerHTML=leng;
        text.innerHTML=val2;         text.focus;
        };
    } 
      }
</script>
</head>
   <div>
      <span id="text1"></span>   
      <img src="css/image.jpg">
      <div>还可以输入
          <span id="number"></span>
          <span >字</span>      </div>
      <textarea id="text"></textarea>
      <span id="sp1">表情</span>
      <span id="sp2">图片</span>
      <span id="sp3">视频</span>
      <span id="sp4">公开</span>
      <input type="button" value="发布" id="but">
    </div> 
</body>
</html>

批改老师:灭绝师太批改时间:2018-11-15 09:08:07
老师总结:前端基本的样式还是要完善的,图片素材都在课件下载中

发布手记

热门词条