AJAX JSON HTML JS 如何输出数据表?
HTML:
<table>
<tr>
<th>Student Name</th>
<th>Student Grades</th>
</tr>
<tr>
<td>
<select name="dropdown" id="dropdown">
<option> - </option>
<option id = "StudentA"> Student A </option>
<option id = "StudentB"> Student B </option>
</select>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<select name="dropdown" id="dropdown">
<option> - </option>
<option id = "StudentA"> Student A </option>
<option id = "StudentB"> Student B </option>
</select>
</td>
<td></td>
<td></td>
</tr>
</table>
JSON:
{"students":
[ {"studentName" : "studentA", "studentGrades" : "gradeC"}, {"studentName" : "studentB", "studentGrades" : "gradeA+"},
]
}
当我选择学生A的下拉选项时,如何使学生成绩自动显示在表格上?
我只解析了响应文本并做了一个控制台日志并完成了它,我让所有学生都在控制台日志上,但不确定如何使用选择选项下拉列表来完成它。
HTML:
<table>
<tr>
<th>Student Name</th>
<th>Student Grades</th>
</tr>
<tr>
<td>
<select name="dropdown" id="dropdown">
<option> - </option>
<option id = "StudentA"> Student A </option>
<option id = "StudentB"> Student B </option>
</select>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<select name="dropdown" id="dropdown">
<option> - </option>
<option id = "StudentA"> Student A </option>
<option id = "StudentB"> Student B </option>
</select>
</td>
<td></td>
<td></td>
</tr>
</table>
JSON:
{"students":
[ {"studentName" : "studentA", "studentGrades" : "gradeC"}, {"studentName" : "studentB", "studentGrades" : "gradeA+"},
]
}
how to make when i select a drop down option of student A then student grades will automatically show on the table ?
i only did parse responsetext and did a console log and got it done i have all the students on the consolelog but not exactly sure how to do it with the select option dropdown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下方法来实现此目的。在选择标签上添加
onchange
事件,并根据所选选项更新成绩列。完整的工作代码:
希望这就是您想要的工作方式。
You can try the below approach to achieve this. Add an
onchange
event on the select tag and based on the selected option update the grades column.Full working code:
Hope that's how you wanted it to work.
您可以通过在 select 上触发
onchange
事件来实现此目的,然后使用Array.filter()
方法过滤掉 Students 数组以获取所选选项studentGrade.
工作演示:
You can achieve it by triggering a
onchange
event on select and then filtered out the students array usingArray.filter()
method to get the selected optionstudentGrade
.Working Demo :