簡體   English   中英

單擊下拉列表時隱藏 label

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM