如果它是空的,我想隐藏我的引导警报.它在页面加载时正确隐藏,问题是当我执行推送时将数据插入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)