使用多个单选按钮显示/隐藏

Show/Hide with Multiple Radio Buttons

本文关键字:显示 隐藏 单选按钮      更新时间:2023-09-26

我对用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服务目录)相关,因此有关如何使用特定CA函数执行操作的问题可能最好在CA服务管理全球用户社区留言板上回答。

但是,作为一个一般的逻辑/JavaScript 问题,除了显示你想看到的字段外,你还需要隐藏你不想看到的字段。 请注意,您的第一个示例调用 ca_fdHideField 来隐藏一组字段,然后调用ca_fdShowField来显示另一组字段。 如果您不想复制大量代码,则可以将它们全部隐藏在if语句之前,然后仅显示与所选单选按钮对应的代码:

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

等。