gpt4 book ai didi

javascript - Element.insert at bottom-1 原型(prototype)

转载 作者:行者123 更新时间:2023-11-29 22:41:38 28 4
gpt4 key购买 nike

我想在他父级的bottom -1位置插入一个Element。

在底部插入以下代码

el.insert({bottom: content})

谢谢

最佳答案

您可以像这样将它插入“最后一个子元素之前”:

el.select('*').last().insert({before:content});

el.select('*')在一个很好的原型(prototype)扩展集合中给出子元素。

last()当然检索该集合的最后一个元素。您可能想单独检索它并确保它不是 undefined (如果没有 child ,这将被返回)在尝试“插入之前”。

此外,IMO 如果可能的话,最好传入一个非通配符选择器。例如,当包含元素是 <ul> 时, 传入 'li' .

链接:
Prototype Element#insert
Prototype Array#last

关于javascript - Element.insert at bottom-1 原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2362788/

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