【发布时间】:2021-11-06 03:12:07
【问题描述】:
清除按钮无法清除list-group history
//html
<button class="btn btn-primary mb-3"
type="button"
id="clear-inputs"
onclick="clearIt()">
Clear history
</button>
<form id="history"></form>
<div class="list-group" id="history"></div>
//javascript clear button function
function clearIt() {
document.getElementById('history').value = "";
}
【问题讨论】:
-
有两个 ID 为
history的元素(无论如何它都是无效的,因为 ID 必须是唯一的)。然后你会得到第一个这样的元素,它是一个空的<form>,并且一个表单没有value。 (请注意,<div>也没有value,因此不清楚您在这里真正尝试做什么......) -
这能回答你的问题吗? Can an HTML element have multiple ids?
标签: javascript button