首页 > 解决方案 > 将禁用输入从真更改为假时,为什么我不能点击输入?

问题描述

我有一个函数可以将输入属性从 true 更改为 false。dom 和 css 更新,但我仍然无法单击或使用输入。

<input id="playerLocation" type="text" name="location" oninput="setPlayerLocation()" disabled="true">
.player-details input[disabled="true"] {
  opacity: 0.6;
}
playerLocation.setAttribute('disabled', false);

标签: javascript

解决方案


您需要removeAttribute用于禁用。

playerLocation.removeAttribute('disabled');
<input id="playerLocation" type="text" name="location" oninput="setPlayerLocation()" disabled="true">


推荐阅读