简体   繁体   English

显示/隐藏多个单选按钮

[英]Show/Hide with Multiple Radio Buttons

I am very new to building forms with js. 我对使用js构建表单非常陌生。 I copied and applied a bit of code to get fields to pop up depending on the Radio button I select. 我复制并应用了一些代码,以使字段弹出,具体取决于我选择的单选按钮。 This works great for two radio buttons, but my issues is that I want to include several (5+) and would like to reset the fields with every change. 这对于两个单选按钮非常有用,但是我的问题是我想包含多个(5+),并且希望每次更改都重置字段。

I was thinking I can input additional code to reset all fields "onchange" but I can't get this piece of code to work... here is what I copied and modified for my use: 我当时想我可以输入其他代码来重置所有字段“ onchange”,但是我无法使这部分代码正常工作……这是我复制和修改的内容:

works great with 2 buttons as designed: 按设计可使用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');
      }
    }
}

Here is what I tried to do: 这是我尝试做的事情:

{
    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')}
        }
    }
}

This appears to be a JavaScript question (not Java) and related to a particular framework (CA Service Catalog), so questions about how to do things with particular CA functions would probably be best answered on the CA Service Management Global User Community message boards. 这似乎是一个JavaScript问题(不是Java),并且与特定框架(CA Service Catalog)有关,因此,有关如何使用特定CA功能执行操作的问题可能最好在CA Service Management全局用户社区留言板上进行解答。

As a general logic/JavaScript question, though, you need to hide the fields you don't want to see in addition to showing the ones you do want to see. 但是,作为一般的逻辑/ JavaScript问题,除了显示您想要查看的字段之外,您还需要隐藏不想查看的字段。 Notice that your first example calls ca_fdHideField to hide one set of fields, then ca_fdShowField to show the other. 请注意,第一个示例调用ca_fdHideField来隐藏一组字段,然后ca_fdShowField来显示另一组字段。 If you don't want to duplicate a lot of code, you could hide them all before the if statements, then just show the one that corresponds with the radio button that was selected: 如果您不想重复很多代码,可以将它们全部隐藏在if语句之前,然后仅显示与所选单选按钮相对应的代码:

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

etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM