html 留言板的删除功能咋添加?


```html
</head>
<body>
    <div class="main">
        <h1>留言板:</h1>
        <div class='mess'>
            <textarea></textarea>
        </div>
        <br>
        <button>OK</button>
    </div>
</body>
<script>
$('treaexta').focus(function(){
    this.value='';
    
});//当鼠标点击留言框时,留言框内部内容清空[]()
$('button').click(function(){
    val=$('textarea').val();
    str="<div class='show'>";
    str+="<div class='close'>&times;</div>";
    str+=val;
    str+="</div>";
    $('.main').append(str);
});//点击button后下方出现留言框的内容
html

$('.close').live('click',function(){
    $(this).parent().hide(1000);
});//点击叉号后隐藏class=show的父标签
</script>






```html

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
</head>

<body>
   <div class="main">
      <h1>留言板:</h1>
      <div class='mess'>
         <textarea></textarea>
      </div>
      <br>
      <button>OK</button>
   </div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
   $('treaexta').focus(function () {
      this.value = '';

   });//当鼠标点击留言框时,留言框内部内容清空[]()
   $('button').click(function () {
      val = $('textarea').val();
      str = "<div class='show'>";
      str += "<div class='close'  >&times;</div>";
      str += val;
      str += "</div>";
      $('.main').append(str);
      // 因为 一开始 没有 close元素 所以要放到 这个 追加万之后 添加点击事件
      if ($('.close').length > 0) { //为了防止 一开始 没有 close 这个dom 报错


         $(".close").click(function () {
            $(this).parent().hide(1000);

         });
      }
   });//点击button后下方出现留言框的内容







</script>

</html>

可以参考一下 。

live事件 一直报错 。
还有就是 你直接 close 添加事件 是不对的,因为 你没有留言时 获取不到 关闭 按钮 。 你需要放到 appendchild之后 再添加事件


<script>
      $("treaexta").focus(function () {
        this.value = "";
      }); //当鼠标点击留言框时,留言框内部内容清空[]()
      $("button").click(function () {
        val = $("textarea").val();
        str = "<div class='show'>";
        str += "<div class='close' onclick='closeFn(this)'>&times;</div>";
        str += val;
        str += "</div>";
        $(".main").append(str);
      }); //点击button后下方出现留言框的内容
      function closeFn(that) {
        $(that).parent(".show").hide();
      }
</script>