我一直通过使用php来回显循环增量变量。现在,我想使用更简单的纯JavaScript。
代替此:
<script>
<?php
echo "<script>";
for ($i = 1; $i <= 48; $i++) {
echo 'X'.$i;
echo '}';
echo "</script>";
?>
我只想要这个:
<script>
for (i = 1; i <= 48; i++) {
document.write (X[i]); //What is the correct syntax for this?
}
</script>
答案 0 :(得分:1)
这是您所需的O / P。 Concat使用“ +”。
function hello()
{
for (i = 1; i <= 48; i++)
{ document.write ('X'+i); }
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
</script>
</head>
<body onload="hello();">
</body>
</html>