1

请参阅示例小提琴

如果您在搜索框中输入任一示例代码,您将获得在 jQuery UI 对话框中弹出的结果。

第一个例子是006

这是代码...

if (ccode == 006) {
    sarcomment = '006';
    sardefinition = 'If you need to make corrections to your information, you may either make them online at www.fafsa.gov, or by using this SAR. You must use your Federal Student Aid PIN to access your record online. If you need additional help with your SAR, contact your school’s financial aid office or visit www.fafsa.gov and click the “Help” icon on the FAFSA home page. If your mailing address or e-mail address changes, you can make the correction online or send in the correction on your SAR. ';
    saractionneeded = 'N/A';
}

紧接着,您将看到代码030的代码。

这是代码...

if (ccode == 030) {
    sarcomment = '030';
    sardefinition = 'We are unable to read all of the information on your FAFSA or SAR because it was damaged. Please review all of the items on this SAR and make any corrections as needed.';
    saractionneeded = 'N/A';
}

代码 006 和 030 的设置相同。我在这里了解到的是,我创建的任何以 0(零)结尾的搜索条件都将导致未定义的查询。

不确定如何解决此问题并寻求您的帮助。

4

2 回答 2

4

在旧的和向后兼容的 JavaScript 版本中以 0 开头的数字是八进制的。

030 = 0*8^2 + 3*8^1 + 0*8^0 = 24

严格模式将八进制数变成语法错误

于 2013-09-23T14:07:29.763 回答
1

这是清理该代码的建议。if您可以使用一个对象将代码映射到信息块上,而不是一长串语句(每一个语句都为一些微妙的错误提供了潜入的机会)。看起来像这样:

function showc_code(ccode){
  var codeTable = {
    '006': {
      definition: 'If you need to make corrections to your information, you may either make them online at www.fafsa.gov, or by using this SAR. You must use your Federal Student Aid PIN to access your record online. If you need additional help with your SAR, contact your school’s financial aid office or visit www.fafsa.gov and click the “Help” icon on the FAFSA home page. If your mailing address or e-mail address changes, you can make the correction online or send in the correction on your SAR. ',
      action: 'N/A'
    },
    '030': {
      definition: 'We are unable to read all of the information on your FAFSA or SAR because it was damaged. Please review all of the items on this SAR and make any corrections as needed.',
      action: 'N/A'
    },
    '040': {
      definition: 'Whatever',
      action: 'Something something'
    },
     // ... other codes ...
  };

  if (codeTable[ccode] != null) {
    sarcomment = ccode;
    sardefinition = codeTable[ccode].definition;
    saractionneeded  = codeTable[ccode].action;
  }
  else {
    // unknown code ... do whatever
  }

  // ... rest of your code to show the dialog ...
}

这样,从代码到相关信息的映射只是数据,没有“移动部件”。

于 2013-09-23T15:40:18.327 回答