我在数据网格中有一个下拉列表框,我需要隐藏或显示它。我可以得到元素。然而,我得到一个错误'Unable to set property 'display‘of undefined or null reference。当我想隐藏它的时候。我尝试使用可见性,但它也有相同类型的错误。有人能教我怎么做吗?谢谢
我的控制:
<asp:dropdownList ID="dropID" runat="server" cssclass="selectColor w175 show"/>
样式表中的类:
.show {
display: normal;
}
.selectColor {
color: #333333; }
.w175 { width:175px; }
我的javascript函数:
function NeedChange(id) {
var dropID = document.getElementById(id);
if (dropID!=undefined ){
//dropID.style.visibility="hidden";
dropID.style.display='none';
}
}
发布于 2016-10-13 10:33:58
这应该是可行的
function NeedChange(id) {
var dropID = document.getElementById(id);
if (dropID!=undefined ){
//dropID.style.visibility="hidden";
$("#dropID").removeClass("show");
}
}
发布于 2016-10-13 15:43:12
你的方法的问题是页面上不存在ID dropID
,你的javascript找不到它。asp.net将重复数据的元素(GridView、ListView、Repeater等)中的ID转换为以下内容:ContentPane1_GridView1_DropDownList1_0
。因此,为了显示/隐藏特定的DropDownList,您需要知道行号。ID的其余部分可以通过下面的命令获得:
<script type="text/javascript">
var myElement = "<%= GridView1.ClientID %>_dropID_" + rowNumber;
// becomes ContentPane1_GridView1_dropID_24
document.getElementById(myElement).style.display = "none";
</script>
棘手的部分是获取行号。这将取决于你的网格设计,以及你为什么和如何隐藏下拉菜单;
https://stackoverflow.com/questions/40010250
复制相似问题