jQuery什么是$(this).parent()。children()

| 只是一个简单的例子:
<p>
    <span class=\"example\"></span>
    <input type=\"text\" name=\"e_name\" id=\"e_id />
</p>
<script type=\"text/javascript\">
    $(\'input\').click(function(){
        $(this).parent().children(\'span\').text(\'Suprise!\');
    }
</script>
我可以改用parent()。children()? 我认为这是一段不太优雅的代码。 是否有任何函数,即:$(this).fun(\'span \')。text(\'just better \'); ??     
已邀请:
        
$(this).siblings(\'span\').text(\'Suprise!\');
    
        
$(this).siblings(\'span\').text(\'Surprise!\');
在不遍历DOM然后回退的情况下将是等效的(我的意思是,它仍然会这样做,但至少您不是手动进行此操作)。     
        elegant3ѭ稍微优雅一点
$(this).prev(\'span\').text(\'Surprise!\');
您可以在这里了解更多信息:上一页 编辑:向后阅读标记,上一个更好,而不是下一个。     
        尝试这个:
$(this).prev(\'span\').text(\'Surprise!\');
    
        
$(\"span.example\",$(this).parent()).text(\'Suprise!\');
    

要回复问题请先登录注册