我正在尝试在单击上创建一个li,并将复选框附加到li。但是,即使我附加了复选框,也无法将其定位(更改)。如何定位最初不在页面上的li的复选框?
const li = document.createElement("li");
li.className = "collection-item";
li.appendChild(document.createTextNode(todoInput.value));
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.style.opacity = "1";
checkbox.className = "delete-item right";
checkbox.style.position = "relative";
li.appendChild(checkbox);
//todoList is ul which is created on page load
todoList.appendChild(li);
我不确定您使用的实例化库,但是复选框会使鼠标指针事件变为none(不确定原因)。
因此在您的js中添加样式pointerEvents
,
checkbox.style.pointerEvents = "auto";