如何在jquery中将visible设置为true

时间:2020-12-14 22:50:15

I am using the following code to hide a dropdown box:

我使用以下代码隐藏下拉框:

  <asp:DropDownList ID="test1" runat="server" DataSourceID="dsTestType" CssClass="maptest1" visible="false"
    DataValueField="test_code" DataTextField="test_desc" AppendDataBoundItems="true" >
    <asp:ListItem></asp:ListItem>
  </asp:DropDownList>   

Somehow I try to show this dropdown by using the following code, but this is just not working for me. Anyone know why?

不知何故,我尝试使用以下代码显示此下拉列表,但这对我不起作用。谁知道为什么?

$("#test1").show();

8 个解决方案

#1


16  

Using ASP.NET's visible="false" property will set the visibility attribute where as I think when you call show() in jQuery it modifies the display attribute of the CSS style.

使用ASP.NET的visible =“false”属性将设置visibility属性,我认为当你在jQuery中调用show()时它会修改CSS样式的display属性。

So doing the latter won't rectify the former.

所以做后者不会纠正前者。

You need to do this:

你需要这样做:

$("#test1").attr("visibility", "visible");

#2


47  

Depends on how you hid it.

取决于你如何隐藏它。

If you used the CSS visibility value then

如果您使用了CSS可见性值

$('#test1').css('visibility', 'visible');

If you used CSS `display'

如果您使用CSS`display'

$('#test1').css('display', 'block'); //or inline or any of the other combos

You might even have made it opacity = 0

您甚至可能使其opacity = 0

$('#test1').css('opacity', '1');

#3


4  

Depends, if i remember correctly i think asp.net won't render the html object out when you set visible to false.

取决于,如果我没记错的话,我认为当你将visible设置为false时,asp.net不会渲染html对象。

If you want to be able to control it from the client side, then you better just include the css value to set it invisible rather than using visible =false.

如果您希望能够从客户端控制它,那么最好只包括css值以将其设置为不可见而不是使用visible = false。

#4


3  

Remove the visible="false" attribute and add a CSS class that is not visible by default. Then you should be able to reference the dropdown by the correct id, for example:

删除visible =“false”属性并添加默认情况下不可见的CSS类。然后你应该能够通过正确的id引用下拉列表,例如:

$("#ctl00_cphTest_test1").show();

Above ID you should serach for in the source of the rendered page in your browser.

在ID以上,您应该在浏览器中的渲染页面的源代码中搜索。

#5


1  

How you made it invisible? Try different approach. Use

你是如何让它隐形的?尝试不同的方法。使用

$("#test1").css('display','none');

When you want to hide that element, and then use

当您想要隐藏该元素,然后使用

$("#test1").css('display','block');

When you wnat to show it.

当你想表现出来的时候。

Or just move these styles into a class and add/remove class.

或者只是将这些样式移动到类中并添加/删除类。

#6


0  

I would be careful with setting the display of the element to block. Different elements have the standard display as different things. For example setting display to block for a table row in firefox causes the width of the cells to be incorrect.

我要小心设置要阻止的元素的显示。不同的元素将标准显示为不同的东西。例如,设置显示以阻止firefox中的表行会导致单元格的宽度不正确。

Is the name of the element actually test1. I know that .NET can add extra things onto the start or end. The best way to find out if your selector is working properly is by doing this.

元素的名称实际上是test1。我知道.NET可以在开始或结束时添加额外的东西。找出您的选择器是否正常工作的最佳方法是这样做。

alert($('#text1').length);

You might just need to remove the visibility attribute

您可能只需要删除visibility属性

$('#text1').removeAttr('visibility');

#7


0  

The problem is that since you are using ASP.NET controls with a runat attribute, the ID of the control is not actually "test1". It's "test1" with a long string attached to it.

问题是,由于您使用带有runat属性的ASP.NET控件,因此控件的ID实际上不是“test1”。它是“test1”,附有长字符串。

#8


0  

Use style="display:none" in your dropdown list tag and in jquery use the following to display and hide.

在下拉列表标记中使用style =“display:none”,在jquery中使用以下内容显示和隐藏。

$("#yourdropdownid").css('display', 'inline');

OR

$("#yourdropdownid").css('display', 'none');

#1


16  

Using ASP.NET's visible="false" property will set the visibility attribute where as I think when you call show() in jQuery it modifies the display attribute of the CSS style.

使用ASP.NET的visible =“false”属性将设置visibility属性,我认为当你在jQuery中调用show()时它会修改CSS样式的display属性。

So doing the latter won't rectify the former.

所以做后者不会纠正前者。

You need to do this:

你需要这样做:

$("#test1").attr("visibility", "visible");

#2


47  

Depends on how you hid it.

取决于你如何隐藏它。

If you used the CSS visibility value then

如果您使用了CSS可见性值

$('#test1').css('visibility', 'visible');

If you used CSS `display'

如果您使用CSS`display'

$('#test1').css('display', 'block'); //or inline or any of the other combos

You might even have made it opacity = 0

您甚至可能使其opacity = 0

$('#test1').css('opacity', '1');

#3


4  

Depends, if i remember correctly i think asp.net won't render the html object out when you set visible to false.

取决于,如果我没记错的话,我认为当你将visible设置为false时,asp.net不会渲染html对象。

If you want to be able to control it from the client side, then you better just include the css value to set it invisible rather than using visible =false.

如果您希望能够从客户端控制它,那么最好只包括css值以将其设置为不可见而不是使用visible = false。

#4


3  

Remove the visible="false" attribute and add a CSS class that is not visible by default. Then you should be able to reference the dropdown by the correct id, for example:

删除visible =“false”属性并添加默认情况下不可见的CSS类。然后你应该能够通过正确的id引用下拉列表,例如:

$("#ctl00_cphTest_test1").show();

Above ID you should serach for in the source of the rendered page in your browser.

在ID以上,您应该在浏览器中的渲染页面的源代码中搜索。

#5


1  

How you made it invisible? Try different approach. Use

你是如何让它隐形的?尝试不同的方法。使用

$("#test1").css('display','none');

When you want to hide that element, and then use

当您想要隐藏该元素,然后使用

$("#test1").css('display','block');

When you wnat to show it.

当你想表现出来的时候。

Or just move these styles into a class and add/remove class.

或者只是将这些样式移动到类中并添加/删除类。

#6


0  

I would be careful with setting the display of the element to block. Different elements have the standard display as different things. For example setting display to block for a table row in firefox causes the width of the cells to be incorrect.

我要小心设置要阻止的元素的显示。不同的元素将标准显示为不同的东西。例如,设置显示以阻止firefox中的表行会导致单元格的宽度不正确。

Is the name of the element actually test1. I know that .NET can add extra things onto the start or end. The best way to find out if your selector is working properly is by doing this.

元素的名称实际上是test1。我知道.NET可以在开始或结束时添加额外的东西。找出您的选择器是否正常工作的最佳方法是这样做。

alert($('#text1').length);

You might just need to remove the visibility attribute

您可能只需要删除visibility属性

$('#text1').removeAttr('visibility');

#7


0  

The problem is that since you are using ASP.NET controls with a runat attribute, the ID of the control is not actually "test1". It's "test1" with a long string attached to it.

问题是,由于您使用带有runat属性的ASP.NET控件,因此控件的ID实际上不是“test1”。它是“test1”,附有长字符串。

#8


0  

Use style="display:none" in your dropdown list tag and in jquery use the following to display and hide.

在下拉列表标记中使用style =“display:none”,在jquery中使用以下内容显示和隐藏。

$("#yourdropdownid").css('display', 'inline');

OR

$("#yourdropdownid").css('display', 'none');