gpt4 book ai didi

javascript - 如何使用 javascript 从列表中删除
  • 转载 作者:行者123 更新时间:2023-11-30 11:12:09 24 4
    gpt4 key购买 nike

    <分区>

    我想做的是使用 javscript 从 DOM 中删除用户点击的任何列表项。这是我的代码:

    // Delete shape from ul event
    shapeList.onclick = function (event) {
    var shapesArray = shapesCtrl.getShapesArray();
    var target = event.target; // Getting which <li> was clicked
    var id = target.parentNode.id; // Getting the value of the li that was clicked
    canvasCtrl.deleteShape(shapesArray, id); // Deleting the targeted element from the array

    var li = shapeList.childNodes;

    // Above i remove the object that the corresponds with the li the user clicked on but i cant remove the actual li itself... Ive tried to use li[id].remove() but it just keeps removing the 1st li even though the id might point to the last item for example.

    };

    谁能帮我用 vanilla js 而不是 jquery 来做这件事。谢谢! :)

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com