是否可以使用Javascript和RegEx隐藏某些HTML元素或页面的某些部分?

时间:2012-09-26 04:39:40

标签: javascript html dom hide

我想知道是否有可能,如果是的话。请有人告诉我如何或只是指向我的教程。 非常感谢。

2 个答案:

答案 0 :(得分:1)

是的只有dom函数

 document.getElementById("p1").style.visibility="hidden"; 

喜欢Ref

<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>

<p id="p1">This is some text.</p>
<input type="button" onclick="displayResult()" value="Hide paragraph" />

</body>
</html>

答案 1 :(得分:0)

这是我的镜头:

你想要的表似乎在div中,div在class = post-body之内。像这样:

<div class="post-body">
    <div dir="ltr">
        <table>
            <tr><td>Ad</td></tr>
            <tr><td>Content</td></tr>
            <tr><td>Ad</td></tr>
        </table>
    </div>
</div>​

我使用jQuery来选择所有行,但是第二个,并像这样隐藏它们

$(document).ready(function(){
    $('div.post-body > div > table tr:not(:nth-child(2))').hide();
})

jsfiddle here:http://jsfiddle.net/qx2GY/