简体   繁体   English

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

[英]how can i use javascript in String in variable?

i'm ready to project 'office reservation'.我已经准备好进行“办公室预订”了。 but i got problem.但我有问题。

i want to change this script to 'for' type.我想将此脚本更改为“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()}');
}

Assuming that '${roomMain.get("' + i + '").getR_endDate()}');假设'${roomMain.get("' + i + '").getR_endDate()}'); is meant to return some HTML string, then what you want to do is to actually execute the expression.意味着返回一些 HTML 字符串,那么您要做的是实际执行表达式。 For example:例如:

for (i = 1; i < 11; i ++) {
  $("#o_status" + i).html(roomMain.get(i).getR_endDate());
}

Note that I'm also assuming the get function accepts a number.请注意,我还假设get function 接受一个数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM