Generate table row break conditionally

后端 未结 1 1074
有刺的猬
有刺的猬 2021-01-24 19:00

I have a

with two cells that I want to display horizontally if device is computer or vertically if it\'s mobile. I borrowed a JS function to detect mo
相关标签:
1条回答
  • 2021-01-24 19:48

    If you want to do only on initial load

    function isMobile() {
        return true; // or false
    }
    
    $(function () {
    
        if (isMobile()) {
            $td = $('#tbl').find('#row1_item2').detach();
            $a = $('#row1').after(`<tr id="row2"></tr>`);
    
            $('#row2').append($td);
        }
    
        $('#row1_item2').css('display', 'table-row');
    })
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <table id="tbl">
        <tr id="row1">
            <td id="row1_item1">a</td>
            <td id="row1_item2" style="display: none;">b</td>
        </tr>
    </table>

    0 讨论(0)
提交回复
热议问题