我有一些 HTML 文本,我在其中传递了一个随机向量中的值。
像这样:
var source = jsPsych.randomization.sampleWithoutReplacement(["source1", "source2", "source3", "source4", "source5"]);
According to the <span style="background-color:' + colour[0] + ' "> ' + source[0] + '</span>, it will raise taxes for the average person by 20,000 Krona, it will result in lost jobs, and it will have no tangible positive impact on the economy until at least 2022.
此“来源”变量与组织名称及其首字母缩略词相关。该首字母缩略词随后在文本中被引用,我想创建一个声明,以便在引用首字母缩略词时它与引用的初始来源相匹配。我尝试使用 if/else if 语句为首字母缩略词创建另一个向量,但没有设法让它工作。
Thus, according to the <span>'+ sourceAc +'</span>, there will be an unresolved deficit for many years to come
有没有一种简单的方法可以做到这一点?
编辑:
我尝试使用 if / else if 语句以及 switch 语句来执行此操作,但输入的值是“未定义”。
这是我尝试过的一种方法:
var sourceAc;
if (source === "Foundation for Economic Education (FEE)") { sourceAc = "FEE";}
else if (source === "Economic Policy Institute (EPI)") { sourceAc = "EPI";}
else if (source === "The Center of Economic and Policy Research (CEPR)") { sourceAc = "CEPR";}
else if (source === "Tax Research Foundation") { sourceAc = "Tax Research Foundation";}
else if (source === "Office of International Economic Affairs (OIEA)") { sourceAc = "OIEA";}
生成的文本应如下所示:
According to the report from the **source1**, the proposed tax increases will hurt businesses. ...
Thus, according to the **source1acronym**, there will be an unresolved deficit for many years to come.