检查元素是否在其提到的类中具有给定元素

时间:2013-09-19 16:06:30

标签: javascript jquery html

<html>
<head>
<script>
function A(){
    $('input[name="B[]"]').each(function() { 
        if(('$(this) .BtnSet .Child input:text[name="A[]"]').length){
         //yes the Child class is inside JRow class and has textboxes with name A[]
        }
    });
    return false;
}
</script>
</head>
<body>
<form onsubmit="return A()">
    <div class="row JRow">
     <input type="text" name="B[]"></input>
     <input type="text" name="B[]"></input>
        <div class="BtnSet">
            <div class="Child">
                <input type="text" name="A[]"></input>
                <input type="text" name="A[]"></input>
            </div>
        </div>
    </div>
    <input type="submit" value="Submit"></input>
</form>
</body>
</html>

我需要检查Child类是否在行JRow类中,如果是,在Child类中是否有任何名称为A []的文本框...

1 个答案:

答案 0 :(得分:2)

尝试

if($('.JRow .BtnSet .Child input:text[name="A[]"]').length){
    //yes the Child class is inside JRow class and has textboxes with name A[]
}