簡體   English   中英

顯示/隱藏多個單選按鈕

[英]Show/Hide with Multiple Radio Buttons

我對使用js構建表單非常陌生。 我復制並應用了一些代碼,以使字段彈出,具體取決於我選擇的單選按鈕。 這對於兩個單選按鈕非常有用,但是我的問題是我想包含多個(5+),並且希望每次更改都重置字段。

我當時想我可以輸入其他代碼來重置所有字段“ onchange”,但是我無法使這部分代碼正常工作……這是我復制和修改的內容:

按設計可使用2個按鈕,效果很好:

{
  toggleSelectionFields: function() {
      var isLaptop = ca_fdIsSelectRadio('showhide','group','short');
      if (isLaptop) {
        ca_fdHideField('showhide','longfields');
        ca_fdShowField('showhide','shortfields');
      } else {
        ca_fdHideField('showhide','shortfields');
        ca_fdShowField('showhide','longfields');
      }
    }
}

這是我嘗試做的事情:

{
    toggleSelectionFields: function() {
        Var discovery = ca_fdIsSelectRadio('phone','deskphone4610','selectproblem','SelectIssue','discovery');
        Var headset = ca_fdIsSelectRadio('phone','deskphone4610','selectproblem','SelectIssue','headset');
        Var fac = ca_fdIsSelectRadio('phone','deskphone4610','selectproblem','SelectIssue','feature');
        Var calls = ca_fdIsSelectRadio('phone','deskphone4610','selectproblem','SelectIssue','calls');
        if (discovery) 
        {ca_fdShowField('phone','deskphone4610','selectproblem','discovermode')}
        if (headset)
        {ca_fdShowField('phone','deskphone4610','selectproblem','headset')} 
        if (fac)
        {ca_fdShowField('phone','deskphone4610','selectproblem','feature')}
        if (calls)
        {ca_fdShowField('phone','deskphone4610','selectproblem','calls')}
        }
    }
}

這似乎是一個JavaScript問題(不是Java),並且與特定框架(CA Service Catalog)有關,因此,有關如何使用特定CA功能執行操作的問題可能最好在CA Service Management全局用戶社區留言板上進行解答。

但是,作為一般的邏輯/ JavaScript問題,除了顯示您想要查看的字段之外,您還需要隱藏不想查看的字段。 請注意,第一個示例調用ca_fdHideField來隱藏一組字段,然后ca_fdShowField來顯示另一組字段。 如果您不想重復很多代碼,可以將它們全部隱藏在if語句之前,然后僅顯示與所選單選按鈕相對應的代碼:

ca_fdHideField(...)
ca_fdHideField(...)
...
if (discovery) {
...
}

等等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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