javascript - 我在我的代码中看不到错误,但整个 javascript 部分不起作用
问题描述
我无法在下拉选项卡中显示任何内容。下拉列表应该是主题或用户名列表中的项目。但是,即使我认为我的编码正确,也没有任何反应。它给了我这个错误消息:“Uncaught SyntaxError: Unexpected token '<'” 我已经寻找这个额外的令牌但似乎找不到它,请帮忙!
<html>
<body>
<?php
//student interface
$file = fopen("subject.csv","r");
$subjects = fgetcsv($file);
fclose($file);
//puts the csv file provided into a 2d array
$studentTable = array();
if (($handle = fopen("students.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$studentTable[] = $data;
} fclose($handle);
}
//creates list that will store list of girls emails
$usernames = array();
//runs through studentTable and appends emails to toEmail.
for ($I = 0; $I < sizeof($studentTable); $I++){
array_push($usernames, $studentTable[$I][0]);
}
?>
<script type="text/javascript">
// Using PHP implode() function to turn the php list into a javascript list
var subjects = <?php echo '["' . implode('", "', $subjects) . '"]' ?>;
var usernames = <?php echo '["' . implode('", "', $usernames) . '"]' ?>;
document.write(subjects);
var select = document.getElementById("userN");
for(var i = 0; i < usernames.length; i++) {
var opt = usernames[i];
var el = document.createElement("option");
//el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
var subchoice = [];
subchoice.push(document.getElementById("choice1"), document.getElementById("choice2"), document.getElementById("choice3"), document.getElementById("choice4"), document.getElementById("choice5"));
for(var x = 0; x < subchoice.length; x++) {
for(var i = 0; i < subjects.length; i++) {
var opt = subjects[i];
var el = document.createElement("option");
//el.textContent = opt;
el.value = opt;
subchoice[x].appendChild(el);
}
}
var six = [];
six = subjects;
six.push("null");
var select = document.getElementById("choice6");
for(var i = 0; i < six.length; i++) {
var opt = six[i];
var el = document.createElement("option");
//el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
</script>
<h2> Select your subjects! </h2>
<form>
<p> Select your name </p>
<select id='userN' name='userN'>
<option>Choose a username</option>
</select>
<p> Select your 1st choice subject </p>
<select id='choice1' name='choice1'>
<option>Choose a subject</option>
</select>
<p> Select your 2nd choice subject </p>
<select id='choice2' name='choice2'>
<option>Choose a subject</option>
</select>
<p> Select your 3rd choice subject </p>
<select id='choice3' name='choice3'>
<option>Choose a subject</option>
</select>
<p> Select your 4th choice subject </p>
<select id='choice4' name='choice4'>
<option>Choose a subject</option>
</select>
<p> Select your 5th choice subject </p>
<select id='choice5' name='choice5' >
<option>Choose a subject</option>
</select>
<p> Select your 6th choice subject (none is an option) </p>
<select id='choice6' name='choice6'>
<option>Choose a subject</option>
</select>
</form>
</body>
</html>
解决方案
推荐阅读
- c# - 有没有办法强制 Intellisense 重新评估可用的过载?
- ios - iOS 崩溃:无法在 Path 中打开领域
- c# - .NET Core 在 Linux 上将客户端证书添加到 POST 到 Kestrel REST API 失败服务器证书验证
- c# - C# 列表
打印项目 - java - 有没有办法调试为什么我的 JavaFX-Project 的可执行 JAR 在我的计算机上运行而不是在其他计算机上运行?(使用 jdk 1.8._051)
- c++ - 复合解引用和赋值的运算符重载
- javascript - 来自 jQuery 回调的数据无法比较
- python - free():无效指针已中止(核心转储)
- r - "," read.csv 中的分隔符 - R
- matlab - 使用方法 extractSurFFeatures 找到包含提取的圆(兴趣点)的矩形区域