<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
       $(".reply").click(function(){
           
                $('.af').fadeIn('slow')
           
        })
   $(".add").click(function(){
var at=$(".replyContent").val()
alert(at)
 })
})
</script>
</head>
<body>
<div id="container">
  <?php
  for($i=0;$i<3;$i++)
   {
   ?>
  <div style=" border-bottom:#CCC 1px solid; margin: 0 auto;">
    <div>
      <?=$i?>
    </div>
    <div></div>
    </span> <span class="reply"><a href="#" >回复</a></span>
    <div style="display:none;" class="af">
      <form>
        <textarea style="width:200px;height:50px; margin:3px 0 0 60px; border:#C90 1px solid;" name="replyContent" class="replyContent"></textarea>
        <div style=" margin-left:150px; margin-top:10px;">
          <input value="提交" type="submit" style="padding:2px; border:#C60 1px solid;" class="add" />
        </div>
      </form>
    </div>
  </div>
  <?
 }
?>
</div>
<!--end#container-->
</body>
</html>问题:只能获取第一个回复框中的内容 下面的回复框输入内容就不能获取到 求解!

解决方案 »

  1.   


    var at;
    $(".replyContent").each({
    at+=$(this).val();
    })
    alert(at);这样试试
      

  2.   

    楼主自己想想这个能返回什么?
    var at=$(".replyContent").val()
      

  3.   

    不知道楼主所谓取不到是什么意思
    楼上说的var at=$(".replyContent").val(),这个返回的一直都是$(".replyContent")第一个Dom元素的value属性,解决方法二楼已经给出,不出处于效率完全没有必要再在里面使用$(this),修改二楼代码如下$(".replyContent").each({
    at+=this.value;
    })
      

  4.   

    $(".add").click(function(){
     $(".replyContent").each(function(){
       var x=$(this).val();
       alert(x); 
    })
    })alert的结果是有3个弹出框 其中有一个是空值 怎么会出现这种情况?