<!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").each(function(){
var x=$(this).val();
alert(x)
})
})
})
</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>
问题:怎样取第一条或第二条的值?each遍历的时候会从上到下遍历 当我点击第一或第二条回复时 总是从第零条开始遍历 我只想取第一条的值 怎样才能避免第零条或第二条的值也给遍历出来了?
比如:我点击第3条回复 如果在第零条和第一条的回复框中输入内容的话 总是会先把第零条和第二条的内容也给遍历出来 这样效率比较低 如果不输入内容 头两次alert出来的是空值 怎样避免多余的遍历 直接把第二条中的回复内容取出来 谢谢!
<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").each(function(){
var x=$(this).val();
alert(x)
})
})
})
</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>
问题:怎样取第一条或第二条的值?each遍历的时候会从上到下遍历 当我点击第一或第二条回复时 总是从第零条开始遍历 我只想取第一条的值 怎样才能避免第零条或第二条的值也给遍历出来了?
比如:我点击第3条回复 如果在第零条和第一条的回复框中输入内容的话 总是会先把第零条和第二条的内容也给遍历出来 这样效率比较低 如果不输入内容 头两次alert出来的是空值 怎样避免多余的遍历 直接把第二条中的回复内容取出来 谢谢!
<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(){
$("span[id^='reply']").click(function(){
$(this).next(".af").fadeIn('slow')
})
$(".add").click(function(){
var at=$(".replyContent").each(function(){
var x=$(this).val();
alert(x)
})
})
})
</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" id="reply<?=$i?>"><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>
var length = $(".replyContent").length;
for(var j = i; j < length; j++){}
即可。
for(var j = i; j < length; j++)
{var x=$(this).eq(i).val();
alert(x)
}这样不行啊 应该怎么写呢?
alert(x);
$(".replyContent").eq(i).val()
$(".add").click(function(){ var length = $(".replyContent").length;
for(var j = i; j < length; j++)
{
alert($(".replyContent")[i].value)
}
})输出的是空值啊
alert($(".replyContent").eq($(".replyContent").length-1).val());})