Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为“设置文本”;“下一步”;使用下一个div中的文本的按钮_Javascript_Jquery_Html - Fatal编程技术网

Javascript 为“设置文本”;“下一步”;使用下一个div中的文本的按钮

Javascript 为“设置文本”;“下一步”;使用下一个div中的文本的按钮,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试将下一个按钮的html设置为下一个div中的内容 <div id="survey-1" class='content'> <h2>Bob</h2> <a href="#" class='next button'></a> </div> <div id="survey-2" class='content'> <h2>Fred

我正在尝试将下一个按钮的html设置为下一个div中
的内容

<div id="survey-1" class='content'>
    <h2>Bob</h2>
    <a href="#" class='next button'></a>                      
</div>

<div id="survey-2" class='content'>
    <h2>Fred</h2>
    <a href="#" class='next button'></a>                      
</div>

<div id="survey-3" class='content'>
    <h2>Joey</h2>
    <a href="#" class='next button'></a>                      
</div>

上下快速移动
弗莱德
乔伊
到目前为止我只有

for (var i = 1; i <= 3; i++) {
        $('.next').html('Next Student '+$("#survey-"+i).children().html());
};
for(var i=1;i检查此项

jQuery jQuery方法-text()方法组合匹配元素集中每个元素的文本内容,包括它们的子元素


检查这个

jQuery jQuery方法-each()方法为每个方法元素循环并执行函数。

请尝试以下操作:

$('.next').each(function(){
  $(this).text($(this).parent().next().find('h2').text());
});

将函数传递给
.text()
,这一点您没有把握。您应该返回新的值来设置它。按照您的方式,您最好使用
。each()
$(document).ready(function(){
    $('.next').each(function(){
       $(this).text($(this).prev('h2').text());
    })
});  
$('.next').each(function(){
  $(this).text($(this).parent().next().find('h2').text());
});