Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
使用jquery隐藏不工作_Jquery_List_Hide - Fatal编程技术网

使用jquery隐藏不工作

使用jquery隐藏不工作,jquery,list,hide,Jquery,List,Hide,我正在尝试做这样的事情: <script type="text/javascript"> $(document).ready(function () { var userType = '<%=Session["UserType"]%>'; if (userType != "Admin") { alert("Inside If Block");

我正在尝试做这样的事情:

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

$(文档).ready(函数(){
var userType='';
if(userType!=“Admin”){
警报(“内部If块”);
$(“#bodycontent”).addClass(“隐藏”);
}
否则{
}
});
但是,正文内容并没有隐藏。我得到的是原样的那一页

请帮忙


如果满足条件,我试图隐藏页面内容

您需要在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>

$(文档).ready(函数(){
var userType='';
if(userType!=“Admin”){
警报(“内部If块”);
$(“#bodycontent”).hide();
}
否则{
}
});
更换

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

试试这个。。。。。 替换


$(文档).ready(函数(){
var userType='';
if(userType!=“Admin”){
警报(“内部If块”);
$(“#bodycontent”).attr(“样式”,“显示:无”);
}
否则{
}
});

警报是否执行?您添加的类实际上没有隐藏任何内容,它是在css中定义的吗?你可以使用
$(“#bodycontent”).hide()
应该是
$(“#bodycontent”).hide()
但是你应该发布一些html工具,它们可能来自
.net
java
。看起来像是经典的ASP.U-duh,当然。我习惯了PHP标签,但忘了它不是。@All..它的MVC不是经典的ASP
  ("#bodycontent").hide();
        $("#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>