【发布时间】:2021-09-28 08:40:30
【问题描述】:
我正在制作一个 HTML 表单,用户在其中提交用户 ID,并且根据该 ID 的第一个字母,它将重定向到网站的特定页面。
该网站是一个 WordPress 网站,每次我测试它时,它都不会转到我的占位符链接(Youtube 和 Reddit),而是根据输入的 ID 转到一个空白的 WP 页面。
例如。提交“A123”会指向 website.com/?participantID=A123 而不是 Reddit(占位符网站)。
这可能是 WP 问题,但感觉好像我没有正确地将输入转换为字符串。老实说,我对我写的任何 JS 都没有信心。感谢任何帮助。谢谢!
<form onsubmit="pageRedirect()">
<input type="text" id="participantID" name="participantID">
<input type="submit">
</form>
<script>
let inputValue = document.getElementById("participantID");
pageRedirect() {
if ("inputValue".startsWith("A")) {
action="https://reddit.com";
}
else {
action="https://youtube.com";
}
}
</script>
【问题讨论】:
-
为什么
"inputValue".startsWith("A")中的"inputValue"周围有引号? - 它是一个变量... -
好的,有道理!老实说,我不确定为什么我将 inputValue 放在引号中。这是漫长的一天,哈哈
标签: javascript html string if-statement conditional-statements