无法定位在之后创建的li内部的复选框

问题描述 投票:1回答:1

我正在尝试在单击上创建一个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);
javascript html dom
1个回答
0
投票

我不确定您使用的实例化库,但是复选框会使鼠标指针事件变为none(不确定原因)。

因此在您的js中添加样式pointerEvents

checkbox.style.pointerEvents = "auto";

Working Codepen here ...

© www.soinside.com 2019 - 2024. All rights reserved.