我正在尝试让 JavaScript 从用户输入(特别是文本框和下拉选项)收集数据,并生成用户输出。任何帮助将不胜感激。
JavaScript 应该收集第一个文本框中的值,将其转换为小写,然后查看它是否是正确的答案。如果是,则应检查用户是否想要有关他们所出演的电影的附加信息("is")或不需要(“否”)。数据库中 Actor 的代码应该显示在第一段中,而 Actor 出演过的电影列表应该显示在第二段中。每部电影都显示在单独的行上。
function gather()
{
var name = document.getElementById("name").value;
return name.toLowerCase();
var info = document.getElementById("info").value;
return info.toLowerCase();
var code = document.getElementById("code").value;
var titles = document.getElementById("titles").value;
if (name = "patrick swayzee")
{
code = "Patrick Swayzee's code is ps01";
if (info = "yes")
{
titles = "Film 1" + \n + "Film 2";
}
else
{
titles = "";
}
}
else
{
code = "Request does not exist. Please enter another actor/actress's name."
}
}
<html>
<head>
<title>Actor/Actress Database</title>
<script src="act_req.js" type="text/javascript">
</script>
</head>
<body>
<table>
<tr>
<td><b>Name:</b></td>
<td><b>Info:</b></td>
<td></td>
</tr><tr>
<td><input type="text" id="name="></input></td>
<td>
<select id="info">
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
</td>
<td><button onclick="gather()">Search</button></td>
</tr>
</table>
<p id="code"></p>
<p id="titles"></p>
</body>
</html>
最佳答案
条件语句中缺少一个额外的=:
if (info == "yes")
事实上,你应该使用 === 这样 jshint 就不会提示它。
关于javascript - 从文本框中获取.value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31946696/