为什么这样做:
$('.button_30').click(function(){ $(this).closest('.portlet').find('.portlet_content').text("foo"); });
任何为什么这不工作:
$('.button_30').click(function(){ $(this).parent('.portlet').find('.portlet_content').text("foo"); });
其中html看起来像这样:
<div class="portlet portlet_30"> <div class="portlet_header portlet_header_30"> header content here </div> <div class="portlet_sub_header portlet_sub_header_30"> <input type="text" class="textBox_30" /> </div> <div class="portlet_content portlet_content_30"> results go here </div> <div class="portlet_footer portlet_footer_30"> <input type="button" class="button_30" /> </div> </div> <div class="portlet portlet_30"> <div class="portlet_header portlet_header_30"> header content here </div> <div class="portlet_sub_header portlet_sub_header_30"> <input type="text" class="textBox_30 /> </div> <div class="portlet_content portlet_content_30"> results go here </div> <div class="portlet_footer portlet_footer_30"> <input type="button" class="button_30" /> </div> </div>