Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果链接没有href,是否隐藏父TR?_Javascript_Jquery - Fatal编程技术网

Javascript 如果链接没有href,是否隐藏父TR?

Javascript 如果链接没有href,是否隐藏父TR?,javascript,jquery,Javascript,Jquery,我现在有: <table> <tbody> <tr> <td> <a href="http://www.google.com">Visit Website</a> </td> </tr> <tr> <td>

我现在有:

<table>
    <tbody>
        <tr>
            <td>
            <a href="http://www.google.com">Visit Website</a>
            </td>
        </tr>
        <tr>
            <td>
            <a href="">Visit Website</a>
            </td>
        </tr>
        <tr>
            <td>
            <a href="http://www.google.com">Visit Website</a>
            </td>
        </tr>
        <tr>
            <td>
            <a href="">Visit Website</a>
            </td>
        </tr>
    </tbody>
</table>
我需要一些javascript来: 如果没有href href=则隐藏包装它的TR

如何使用javascript实现这一点?

如果您只想检查href= 试一试

$('a[href=""]').parent().parent().hide();
$('a[href=""],a:not([href])').parent().parent().hide();

如果您还想只检查href=或不检查给定的href属性 试一试

$('a[href=""]').parent().parent().hide();
$('a[href=""],a:not([href])').parent().parent().hide();

您可以使用href=获取标记,然后使用 $'a[href=]'。最近的'tr'。隐藏;
现在就看一看它的工作原理,请检查一下

只是为了学究,从技术上讲,你不能说它没有href。