Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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
使用jQuery prev()方法获取H2的文本?_Jquery_Jquery Selectors - Fatal编程技术网

使用jQuery prev()方法获取H2的文本?

使用jQuery prev()方法获取H2的文本?,jquery,jquery-selectors,Jquery,Jquery Selectors,似乎无法让它工作。有什么想法吗 在使用输入字段作为起始位置时,我试图获取出现在之间的文本 jQuery: $(".title input").each(function(){ alert( $(this).prev('h2').text() ); } Html: 英语(美国) 头衔* 使用.prev()访问兄弟姐妹。通过向链中添加.parent(),可以访问父元素的同级 $(".title input").each(function() { alert( $(this).pa

似乎无法让它工作。有什么想法吗

在使用输入字段作为起始位置时,我试图获取出现在
之间的文本

jQuery:

$(".title input").each(function(){
    alert( $(this).prev('h2').text() );
}
Html:


英语(美国)
头衔*
使用
.prev()
访问兄弟姐妹。通过向链中添加
.parent()
,可以访问父元素的同级

$(".title input").each(function() {
    alert( $(this).parent().prev('h2').text() );
});

使用
.prev()
访问兄弟姐妹。通过向链中添加
.parent()
,可以访问父元素的同级

$(".title input").each(function() {
    alert( $(this).parent().prev('h2').text() );
});

试试这样的


试试这样的

谢谢!我想可能是那样的。谢谢!我想可能是那样的。谢谢!我准备跳过这个,使用另一种方法。你救了我,谢谢!我准备跳过这个,使用另一种方法。你救了我。
$(".title input").each(function() {
    alert( $(this).parent().prev('h2').text() );
});
jQuery("h2").each(function(i, obj){            
     alert(obj.textContent);                
});