JQuery .Show()不能与服务器控件一起使用?

时间:2010-11-01 12:40:22

标签: asp.net jquery show-hide

我有2个html TR我制作它们runat="server"& visible="false"我有一个名为citiesDropDownList

的下拉列表
$(document).ready(function() {
$('#<%=citiesDropDownList.ClientID %>').change(function() { ValidateCity(); });
});

并在更改此下拉列表时,我检查其文本是否等于字符串我显示2 tr如下

function ValidateCity() {
        if ($('#<%= citiesDropDownList.ClientID %> :selected').text() == identity_CityOther)   {
            $('#<%= otherCityTR.ClientID %>').show();
            $('#<%= areasTR.ClientID %>').show();
        }
        var city = $('#<%= citiesDropDownList.ClientID %>').val();
        return IsValid((city.length != 0), '#<%= cityDiv.ClientID %>', identity_CityRequired);
    }

.show()根本不起作用,我不是理由..能不能引导我解决问题?

仅供参考:我尝试了$('#<%= otherCityTR.ClientID %>').show('slow');$('#<%= otherCityTR.ClientID %>').css('visibility', 'visible');,但它也不起作用......

3 个答案:

答案 0 :(得分:9)

visible="false"表示它甚至无法呈现到页面中,因此您的选择器找不到任何元素。

而不是visible="false"使用style="display: none;"隐藏元素,但仍然在页面中呈现它们。

答案 1 :(得分:3)

如果在服务器控件上设置visible = "false",则控件甚至不会呈现给浏览器。改为设置display: none,然后在您的javascript中使用display: block显示控件。

答案 2 :(得分:1)

从服务器控件中删除visible = false,因为这会停止向页面呈现控件,要么使用display:none设置CSS样式,要么在javascript中隐藏所需的控件。

相关问题