隐藏不使用jquery

时间:2013-10-22 11:26:53

标签: jquery list hide

我正在尝试这样做:

 <script type="text/javascript">
        $(document).ready(function () {
            var userType = '<%=Session["UserType"]%>';
            if (userType != "Admin") {
                alert("Inside If Block");
                $("#bodycontent").addClass("hide");
            }
            else {
            }
        });
    </script>

但是,身体内容并没有隐藏。我正在获取该页面..

请帮助..

如果condditon满意,我试图隐藏页面内容

3 个答案:

答案 0 :(得分:1)

您需要在css上定义类隐藏,如:

.hide { display: none; }

或者干脆就这样做:

 <script type="text/javascript">
        $(document).ready(function () {
            var userType = '<%=Session["UserType"]%>';
            if (userType != "Admin") {
                alert("Inside If Block");
                $("#bodycontent").hide();
            }
            else {
            }
        });
    </script>

答案 1 :(得分:1)

替换

  $("#bodycontent").addClass("hide"); 

  ("#bodycontent").hide();

答案 2 :(得分:0)

试试这个...... 替换

        $("#bodycontent").addClass("hide");

        $("#bodycontent").attr("style","display:none");

...

<script type="text/javascript">
        $(document).ready(function () {
            var userType = '<%=Session["UserType"]%>';
            if (userType != "Admin") {
                alert("Inside If Block");
                $("#bodycontent").attr("style","display:none");
            }
            else {
            }
        });
    </script>