【发布时间】:2011-12-02 22:49:20
【问题描述】:
感谢您的关注。
我还在学习更复杂的 javascript 和 jquery 编码,所以可以通过一些帮助来做,因为我不知道以下内容,或者即使它可能!
我需要一种更好/更简单/更短的方法来执行以下操作(请注意我已经删除了不相关的验证等编码): '
function Findbox5( myform, box1, box2, box3, box4, box5, Storeall, s1, s2, s3, s4, s5)
{
//store values
Myform = document.forms.myform;
box1 = Myform.box1.value;
box2 = Myform.box2.value;
box3 = Myform.box3.value;
box4 = Myform.box4.value;
box5 = Myform.box5.value;
s1 = Myform.s1.value;
s2 = Myform.s2.value;
s3 = Myform.s3.value;
s4 = Myform.s4.value;
s5 = Myform.s5.value;
//set as one string
Storeall = s1 + ":" + box1 + ";" + s2 + ":" + box2 + ";" + s3 + ":" + box3 + ";" + s4 + ":" + box4 + ";" + s4 + ":" + box5 + ";" ;
// next function...
} '
如您所见,我有 5 个输入框和每个框的相关选择(每个选择有 4 个选项:1、2、3、4。)。当用户在框中输入数据时,他们会选择相关选项。必须输入所有框和选项,然后他们才能提交表格。
此数据将作为存储在 storeall 下的变量通过电子邮件发送给我。这将类似于 1:1234;2:1324;1:3232;4:5434;2:3211;
所以我希望做的是使用单独的函数或相同的函数将这些数据简化为以下数据:1:1234-3232;2:1324-3211;4:5434;
这可能吗?还是我做了最简单的方法?
欢迎任何 cmets 或帮助,再次感谢
【问题讨论】:
-
如果函数不会对参数值做任何事情但会覆盖它们,为什么还要接受参数?
标签: javascript jquery sorting grouping simplify