如何在变量的字符串中使用javascript?

如何在变量的字符串中使用javascript?,javascript,jquery,Javascript,Jquery,我已准备好进行“办公室预订”项目。 但我有问题 我想将此脚本更改为“for”类型 $("#o_status2").html('${roomMain.get("02").getR_endDate()}'); $("#o_status3").html('${roomMain.get("03").getR_endDate()}'); $("#o_status4").html('${roomMain.get("04").getR_endDate()}'); $("#o_status5").html('$

我已准备好进行“办公室预订”项目。 但我有问题

我想将此脚本更改为“for”类型

$("#o_status2").html('${roomMain.get("02").getR_endDate()}');
$("#o_status3").html('${roomMain.get("03").getR_endDate()}');
$("#o_status4").html('${roomMain.get("04").getR_endDate()}');
$("#o_status5").html('${roomMain.get("05").getR_endDate()}');
$("#o_status6").html('${roomMain.get("06").getR_endDate()}');
$("#o_status7").html('${roomMain.get("07").getR_endDate()}');
$("#o_status8").html('${roomMain.get("08").getR_endDate()}');
$("#o_status9").html('${roomMain.get("09").getR_endDate()}');
$("#o_status10").html('${roomMain.get("10").getR_endDate()}');

for (i = 1; i < 11; i ++) {
    $("#o_status"i).html('${roomMain.get("' + i + '").getR_endDate()}');
}
$(“#o#u status2”).html('${roomMain.get(“02”).getR_endDate()');
$(“#o#u status3”).html(“${roomMain.get(“03”).getR_endDate()”);
$(“#o#u status4”).html('${roomMain.get(“04”).getR_endDate()}');
$(“#o#u status5”).html(“${roomMain.get(“05”).getR_endDate()”);
$(“#o#u status6”).html(“${roomMain.get(“06”).getR_endDate()”);
$(“#o#u status7”).html(“${roomMain.get(“07”).getR_endDate()”);
$(“#o#u status8”).html('${roomMain.get(“08”).getR_endDate()}');
$(“#o#u status9”).html(“${roomMain.get(“09”).getR_endDate()”);
$(“#o#u status10”).html(“${roomMain.get(“10”).getR_endDate()”);
对于(i=1;i<11;i++){
$(“#o#u status”i).html(“${roomMain.get(“+i+”).getR_endDate()”);
}

假设
'${roomMain.get(“+i+”).getR_endDate()}')
意味着返回一些HTML字符串,然后您要做的是实际执行表达式。例如:

for (i = 1; i < 11; i ++) {
  $("#o_status" + i).html(roomMain.get(i).getR_endDate());
}
(i=1;i<11;i++)的
{
$(“#o#u status”+i).html(roomMain.get(i.getR#u endDate());
}

注意,我还假设
get
函数接受一个数字

您的代码中有一些拼写错误
$(“#o#u status”i)
可能应该是
$(“#o#u status”+i)
。此外,您可能不希望在诸如
'${roomMain.get(“02”).getR_endDate()}'
之类的内容周围使用单引号。试试倒勾。谢谢,我改了$(“#o#u status”+i)。我已经试过了${roomMain.get(“01~10”).getR_endDate()}。我得到了彼此的所有结果。那我怎么改成“换”型呢?谢谢,太棒了!我试过背部抽搐。成功。这意味着返回像“2020-04-22”这样的结束日期。我试着做“办公室预订”get(“01~10”)表示房间号,并制作“地图”类型01~10'正在生成。该数字彼此为1~10,值为01~10。如果我更改了构造,我会尝试它。我更改了“map”类型->“list”类型,并使用了反勾号。然后是成功。谢谢