使用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>