[英]Hiding a label when drop-down list is clicked
一旦任务完成,我将在下拉列表下方显示 label,并且我希望 label 在下拉列表中选择新任务时隐藏而不发回。
我试过使用lblMessage.Text = "";
但目前有:
<asp:DropDownList ID="ddlJob" runat="server" AutoPostBack="false" CssClass="combobox"
DataTextField="name" DataValueField="name" OnClick="hideOnKeyPress(); return true;">
</asp:DropDownList>
function hideOnKeyPress() {
document.getElementById('lblMessage').style.display = 'none';
}
预期:Label 在任务完成后出现,并在选择新任务时隐藏。
实际:Label 一旦任务完成就会出现,但会一直保持到下一个选定任务完成。
我认为您需要访问 OnChangeEvent,因此当您更改下拉选项时,将调用 function。
<asp:DropDownList Id="ddlJob" runat="server" AutoPostBack="false" OnSelectedIndexChanged="SelectedChange"
onchange="ddlChanged(this);"/>
在 function 中,如果将当前索引值存储到隐藏字段中,即使在页面上回发后也将拥有它。 因此,如果您在页面上有任何回发,您仍将拥有该值。 回想起来,如果您有多个不同的值,您需要检查它们之前是否出现过,您可以将一个连接字符串与以前的值进行比较。
就像是:
function ddlChanged(ddl){
var newIndex = true;
var previousIndices = $('hdnIndex').value;
var currentIndex = String(ddl.selectedValue);
//if no values exist before then just take the current index
if (previousIndices == null)
previousIndices = (currentIndex);
else{
//else loop through the previous indices to check if the value has appeared before.
var indexArray = previousIndices.split(",");
for(i=0; i < indexArray.length; i++){
if (indexArray[i] == currentIndex)
newIndex = false;
}
if(newIndex){
document.getElementById('lblMessage').style.display = 'none';
previousIndices+= "," + currentIndex;
}
}
像这样的东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.