【发布时间】:2020-09-17 15:25:15
【问题描述】:
我添加了以下功能,以便在单击清除按钮时简单地删除字段。我得到的错误是:
未捕获的类型错误:无法读取 null 的属性“classList”
为了解决这个问题,我尝试在输入字段的 div 中添加 positionInput 类;这当然没有解决。
_clear() {
var newPosition = document.getElementById("position");
newPosition.classList.remove("positionInput");
}
这是注入新表单输入字段的对象:
_addPosition(e) {
let newPosition = document.createElement('input');
newPosition.classList = 'positionInput';
positionGroup.insertAdjacentElement('beforeend', newPosition);
}
这是输入字段和清除按钮的标记
<div style="display: flex; margin: 0.5em 0 1em 0;">
<input style="margin-right: 10px;" type="button" value="SAVE" on-click="_post" />
<input type="button" value="CLEAR" on-click="_clear" />
</div>
【问题讨论】:
-
我也应该为输入字段添加html:
标签: javascript html event-handling polymer dom-events