javascript - 将两个变量合并为一个变量并与另一个变量相等
问题描述
该代码没有任何错误,但不起作用。我填写了两个输入并单击按钮,但它没有打印出单词。
let listItem = document.getElementById('todoListItem');
let timeInputValue = document.getElementById('timeInput');
let getInputValue = document.getElementById('task');
let errorMessageInput = document.getElementById('errorMsg');
function addTask() {
if (getInputValue.value.trim() === "") {
errorMessageInput.textContent = "You haven't added a todo item, please add it in order to show up";
return;
}
let myTodoInput = listItem.textContent;
let myTodoTime = timeInputValue.textContent;
let myTodoInfo = myTodoInput + ' Time ' + myTodoTime;
myTodoInfo = getInputValue.value;
}
<div class="myApp border border-info">
<p class="text-center appTittle">To Do List</p>
<div class="todoThings" id="todo">
<ul>
<li id="todoListItem"></li>
</ul>
</div>
<div class="row mx-auto">
<p class="mr-3 ml-3 appTaskText">Task</p><input type="text" class="appInput" id="task">
<p class="mr-1 ml-3 appTaskText">Time</p><input type="number" id="timeInput" min="1" max="24">
</div>
<button type="submit" class="btn btn-info btn-sm addButton" id="add" onclick="addTask()">Add task</button>
<p id="errorMsg" class="text-danger mt-1 mb-1"></p>
</div>
解决方案
我解决了我的问题这是修复
let listItem = document.getElementById('todoListItem');
let timeInputValue = document.getElementById('timeInput');
let getInputValue = document.getElementById('task');
let errorMessageInput = document.getElementById('errorMsg');
function addTask() {
if (getInputValue.value.trim() === "") {
errorMessageInput.textContent = "You haven't added a todo item, please add it in order to show up";
return;
}
let myTodoInput = getInputValue.value;
let myTodoTime = timeInputValue.value;
let myTodoInfo = myTodoInput + ' at ' + myTodoTime + 'PM';
listItem.textContent = myTodoInfo;
}
推荐阅读
- python - 如何从 Alpaca Trade API BarSet 获取原始数据?
- django - 如何构建 Django 权限以拥有多个类别的权限组?
- python - 如何将 str 转换为字节
- c++ - 如何将 CString 转换为使用 WCHAR 的 Windows API 和自定义函数?
- c - C Sockets 聊天室(客户端/服务器)卡在读取/接收
- c# - 转换块链接到多个目标,谓词未按预期工作
- python-3.x - 如何修复“类型错误:+:'int'和'list'不支持的操作数类型”
- reactjs - 使用 Array.prototype.find() 显示来自 Redux 存储的信息会导致错误
- javascript - 比较多个连续生成的数组的方法?
- javascript - 将 JSON 处理为表格布局的特定行