简体   繁体   English

我如何在asp.net mvc中隐藏div

[英]How do i hide div in asp.net mvc

I have 3 div which are: 我有3个div是:

<div class="widgetbox" id="divone">Content 1</div>

<div class="widgetbox" id="divtwo">Content 2</div>

<div class="widgetbox" id="divthree">Content 3</div>

I need to hide two of these div so that I can make a condition to decide which to appear and which to hide later on. 我需要隐藏其中的两个div,以便我可以决定出现哪个以及稍后要隐藏哪个。 I tried to hide it like below, but it doesn't work. 我试图隐藏它,如下所示,但它不起作用。 I think I'm using mvc 4. sorry for bad english. 我想我正在使用mvc 4.对不起英语不好。

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>

Here you get two answers: 在这里你得到两个答案:

1) 1)

<script type='text/javascript'>
    $(document).ready(function(){
        $("#divtwo").hide();
        $("#divthree").hide();
    });
</script>

2) try this one. 2)尝试这个。 No need any references. 不需要任何参考。

<script type='text/javascript'>
    window.onload=function(){
        document.getElementById("divtwo").style.display='none';
        document.getElementById("divthree").style.display='none';
    }
</script>

First you need to add jQuery reference. 首先,您需要添加jQuery引用。 Here you is way to get latest jQuery in your project 在这里,您可以在项目中获取最新的jQuery

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

then your code will work for .hide() 那么你的代码将适用于.hide()

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM