如何使用按钮关闭合拢

时间:2018-10-28 09:14:40

标签: jquery css

如何使用按钮折叠折叠?

public static IEnumerable<PropertyInfo> GetPropertiesRecursive(this Type type)
{
    var visitedProps= new HashSet<string>();

    IList<PropertyInfo> propertyInfos = new List<PropertyInfo>();

    var currentTypeInfo = type.GetTypeInfo();

    while (currentTypeInfo.AsType() != typeof(object))
    {
        var unvisitedProperties = currentTypeInfo.DeclaredProperties.Where(p => p.CanRead &&
                                                                             p.GetMethod.IsPublic &&
                                                                             !p.GetMethod.IsStatic &&
                                                                             !visitedProps.Contains(p.Name));

        foreach (var propertyInfo in unvisitedProperties)
        {
            visitedProps.Add(propertyInfo.Name);

            propertyInfos.Add(propertyInfo);
        }

        currentTypeInfo = currentTypeInfo.BaseType.GetTypeInfo();
    }

    return propertyInfos;
}

我也在javascript中尝试过

<div class="container">
    <div class="col-md-4">

    <button class="btn btn-default" data-toggle="collapse" data-target="#contents" type="button">
            Collase stuff
        </button>
        <div class="collapse" id="contents">
            Some content
        </div>
        <button id="cls">CLose</button>
    </div>

</div>

1 个答案:

答案 0 :(得分:1)

您已写出条件,如果e.target不等于关闭按钮然后执行,则不正确。因此,只需删除“!”从if条件开始。

$(document).click(function(e){
    if($(e.target).is('#cls')){
        $('.collapse').collapse('hide');
    }
});
相关问题