Home  >  Q&A  >  body text

javascript - jquery shows and hides "No data yet" based on the length of the returned data

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中文网2667 days ago655

reply all(3)I'll reply

  • 某草草

    某草草2017-06-30 09:59:43

    if (!result) {
        $('.isNoData').show()
    } else {
        // 渲染数据
    }
        

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-30 09:59:43

    res = json_encode(['count'=>0]);
    $.get('/path/to/file', function(res) {
        if(res.count == 0){
            $('. isNoData').show();
        }
    });

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-30 09:59:43

    $.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();//显示暂无数据的行
            }
        }
    
    })

    reply
    0
  • Cancelreply