javascript - jquery shows and hides "No data yet" based on the length of the returned data
PHP中文网
PHP中文网 2017-06-30 09:57:43
0
3
651

Request data from the background to render the front-end table. If the data length returned by the background is 0, "No data yet" will be displayed in the table.
I have already written it in html

<tr class="isNoData"><td colspan="8" style="height:24px;line-height:24px;font-size:12px;">暂无数据</td>

Because in the initial state, this line is not displayed, so the isNoData class is written with display: none, but how to dynamically control it now?
There is a select box on the page. Select one of the items and click the search button, and the data will be requested again

Maybe there is something wrong with my question statement. Every time this select selects a state, click Search or re-request data. Once "No Data" appears, "No Data" will always exist no matter how you switch it. Finally, please use this function. Adding $(".isNoData").hide(); at the beginning solves this problem.
Special thanks to the students who answered the questions! !
When you encounter problems, you should think calmly

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
某草草
if (!result) {
    $('.isNoData').show()
} else {
    // 渲染数据
}
    
世界只因有你
res = json_encode(['count'=>0]);
$.get('/path/to/file', function(res) {
    if(res.count == 0){
        $('. isNoData').show();
    }
});
给我你的怀抱
$.ajax({//获取后台数据,默认异步
    cache:false,
    url:'url地址',
    type:'get',
    dataType:'json',
    beforeSend:function () {
        //注:同步ajax请求时,此处内容在IE浏览器不执行
        //展示过度动画
    },
    success:function (data) {
        if(data.length > 0){
            $('.isNoData').hide();//隐藏暂无数据的行
            //处理数据并展示
        }else{
            $('.isNoData').show();//显示暂无数据的行
        }
    }

})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!