且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery迭代并删除空的HTML表行

更新时间:2023-12-04 13:53:18

您的代码似乎正常运行.尝试单独运行以下命令以了解我的意思:

Your code appears to work just fine. Try running the following on its own to see what I mean:

<html>
<head>
    <title>jQuery Tests</title>

    <script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('tr').each(function () {
                $(this).find('td').each(function () {
                    if ($(this).text().trim() == "") {
                        $(this).closest("tr").remove();
                    };
                });
            });
        });
    </script>

</head>
<body>
    <table cellpadding="0" cellspacing="0" border="1">
        <tr>
            <td></td>
            <td>testing</td>
        </tr>
        <tr>
            <td>testing</td>
            <td>testing</td>
        </tr>
        <tr>
            <td>testing</td>
            <td>   </td>
        </tr>
    </table>
</body>

页面上是否还有其他可能冲突的东西?

Could there be something else on the page that might be conflicting?