2011-08-26 69 views

回答

3
if($("#A").siblings().first().children("input[type='checkbox']").length > 0) { 
    //code 
} 
+0

if($(“#A”)。siblings()。first()。children(“input [type ='checkbox']”)。length应该返回0.然而它应该返回1. – techlead

+0

It在这里工作。我复制你提供的标记和我的javascript:http://jsfiddle.net/Uv9Js/ – Dennis

+0

哎呀..!对不起,是的,它的作品。我引用一个 “A” 级,而不是在$ ID为 “A”( “#A”)。谢谢! – techlead

1

试试这个

如果你知道兄弟是元素

if($("#A").next().chldren(":checkbox").length){ 
    //Yes I am a checkbox 
} 

低于或者如果上述

if($("#A").prev().chldren(":checkbox").length){ 
    //Yes I am a checkbox 
} 

或者,如果你不知道

if($("#A").siblings(":first").chldren(":checkbox").length){ 
    //Yes I am a checkbox 
} 
+0

($( “#A”)的兄弟姐妹( “:第一个”)chldren( “:复选框”。)长度)将返回0。然而,它应该返回1. – techlead

0
if($('#A').prevAll().has(':checkbox').length>0) { 
//code 
} 
+1

我想'.prevAll()'应使用而不是'.prev()' – fen1x

+0

你说得其实我错过了的div之一。现在修复 – Drafter