小编Led*_*ing的帖子

如果空无效则隐藏引导警报

如果它是空的,我想隐藏我的引导警报.它在页面加载时正确隐藏,问题是当我执行推送时将数据插入div,它不会显示警报并且保持不变display = none

在此输入图像描述

HTML

 <div id="a1" class="alert alert-success">
                <div id="discussion"></div>
            </div>
Run Code Online (Sandbox Code Playgroud)

JS:

<script type="text/javascript">
    hideAlert("a1");

    function hideAlert(id) {
        var text = $('#' + id + '#discussion').text();
        console.log(text.length);
        if (text.length <= 0)
            $('#' + id).hide();
    }
</script>
Run Code Online (Sandbox Code Playgroud)

编辑

我尝试使用它input event,它发生相同.它隐藏但是在获得价值时没有显示

JS:

<script type="text/javascript">
    $('#discussion').keyup(function () {

        // If value is not empty
        if ($(this).val().length == 0) {
            // Hide the element
            $('#a1').hide();
        } else {
            // Otherwise show it
            $('#a1').show();
        }
    }).keyup();


</script>
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

3
推荐指数
1
解决办法
1543
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1