【发布时间】:2017-05-17 15:16:58
【问题描述】:
我是 JS 新手。
我想在 JS 中编写一个 for 循环,它会给出选定数量的表单。 这是我到目前为止得到的。 (也许我必须写一个函数。但我不知道如何继续。)
<!DOCTYPE html>
<html lang="de">
<head>
<title>Survey</title>
<link rel="stylesheet" type="text/css" href="survey.css">
</head>
<body>
<h1><?php echo "Title: ".$_POST["title"];
?></h1>
<script>
var Ausgabe = "";
for (var i = 1; i <= <?php echo $_POST["anzahl"];?>; i++){
Ausgabe = i + ". question: " + <form>
<input type="text" id="title" name="title">
</form>
document.write(Ausgabe)
}
</script>
</body>
</html>
欢迎任何提示。
【问题讨论】:
-
您似乎忘记将字符串放在引号中,导致语法错误。您还可以通过重复使用相同的
id来生成无效的 HTML。 -
你想给 JavaScript 表单值吗?
标签: javascript php html for-loop