【问题标题】:Remove form input field when clear button is clicked单击清除按钮时删除表单输入字段
【发布时间】: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


【解决方案1】:

你可以尝试输入类型重置,或者清除按钮上的重置功能

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 2021-09-25
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    相关资源
    最近更新 更多