使用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);
});