gpt4 book ai didi

javascript - 为什么 JavaScript 找不到我的输入文本?

转载 作者:行者123 更新时间:2023-12-02 17:29:10 24 4
gpt4 key购买 nike

我正在编写一个番茄钟 ( http://pomodorotechnique.com/ ) 风格的计时器,我试图找出为什么我的代码不起作用。我试图从输入中获取文本,但我的代码不断返回到我的默认设置。

我的 JavaScript

function task() {
taskReminderText = document.getElementById("form.taskReminder").value;
timeInput = document.getElementById("form.timerLenght").value;
}

我的html

<form id="form" onsubmit="checkForm()">
Task Reminder: <input id="taskReminder" type="text" name="taskReminder"><br>
Timer Length is <input id="timerLength" placeholder="20" type="text" name="timerLength"> minutes.<br>
<input type="submit" value="Submit" onsubmit="task()">
</form>

最佳答案

使用 document.getElementById()时,您只需要提供id值即可:

function task() {
taskReminderText = document.getElementById("taskReminder").value;
timeInput = document.getElementById("timerLenght").value;
}

关于javascript - 为什么 JavaScript 找不到我的输入文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23224897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com