Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        3年前关闭。
                    
                
        

我尝试检查li中是否有带有查找子项的标签,但是我是新手,不能正确执行,我知道这很简单,但是我在Jquery中是新手:

HTML:

<li class="dropdown open">
    <div class="dropdown-toggle">
        Something
    </div>
    <ul>
        <li>
            <input id="test" type="checkbox" value="Test" class="checkbox">
            <label for="test">Test</label>
        </li>
    </ul>
</li>

最佳答案

您可以检查length

if( $('li').find('label').length )
    //exist
else
    //does not exist


希望这可以帮助。



if( $('li').find('label').length )
  console.log('Label exist');
else
  console.log('Label does not exist');

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="dropdown open">
    <div class="dropdown-toggle">
        Something
    </div>
    <ul>
        <li>
            <input id="test" type="checkbox" value="Test" class="checkbox">
            <label for="test">Test</label>
        </li>
    </ul>
</li>

10-02 16:03