具有多个单选按钮的表单的最有效的编码样式 [英] Most efficient coding style for forms with multiple radio buttons

查看:102
本文介绍了具有多个单选按钮的表单的最有效的编码样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的表格:

I am have a form that look something like this:

我想要input.variable,我要根据填写的框数和选中的单选框将其放入localStorage.适用如下:

-单选按钮-
一个名字输入:
na:名称
F:姓名和朋友
F +姓名和朋友

I want the input.variable I am going to throw into localStorage based on the number of boxes filled out and the radio boxes checked. It would apply as follows:

-Radio Buttons-
One Name Typed in:
na : Name
F: Name and friend
F+ Name and friends

键入两个名称:
na:名称和名称
F:姓名,姓名和朋友
F +:姓名,姓名和朋友

Two Names typed in:
na: Name and Name
F: Name, Name and friend
F+: Name, Name and friends

键入三个名称:
na:名称,名称和名称
F:姓名,姓名和朋友
F +:姓名,姓名,姓名和朋友

Three Names typed in:
na: Name, Name and Name
F: Name, Name Name and friend
F+: Name, Name, Name and friends

键入的四个名称:
na:名称,名称,名称和名称
F:姓名,姓名,姓名,姓名和朋友
F +:姓名,姓名,姓名,姓名和朋友

Four Names typed in:
na: Name, Name, Name and Name
F: Name, Name, Name, Name and friend
F+: Name, Name, Name, Name and friends

解决此问题的最佳方法是什么?我正在尝试一种最有效的方式来编写多个if/then/else语句之外的内容.

What would be the best way to approach this? I am trying to think of the most efficient way to write this beyond multiple if/then/else statements.

谢谢

推荐答案

好吧,由于我的评论似乎为您指明了正确的方向,因此我将其粘贴在此处作为答案:

Ok, since my comment seems to have pointed you in the right direction, I'm pasting it here as an answer:

如果您想要一种干净的方式来排列数据,请使用对象文字.如果要处理if elseif elseif语句,请考虑使用switch,如果所有条件检查的值都不同,则只需使用switch (true)

if you want a clean way to arrange data, use an object literal. If you're dealing with a wash of if elseif elseif statements, consider using a switch, if all conditionals check a different value, just use switch (true)

这篇关于具有多个单选按钮的表单的最有效的编码样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆