gpt4 book ai didi

javascript - 将多个内部子节点传递给函数

转载 作者:行者123 更新时间:2023-11-30 10:43:39 25 4
gpt4 key购买 nike

我需要将内部 div 的内容传递给函数,例如 myfun(string)。我试过使用

myfun((this).children[0].innerHTML)

myfun((this).children[1].innerHTML)

myfun((this).children[0].children[0].innerHTML)

但这些似乎都不起作用。我不能只传递 getElementById 值,因为该函数应该是通用的,因为它会被 php 在各种 <a> 上调用。元素(理想情况下,我认为它应该包含 this. 关键字)。

enter image description here

感谢您的帮助。

最佳答案

如果您不需要它来跨浏览器工作,则有:

this.getElementsByClassName('label')[0]

这将在 IE 8 and below 中失败.

如果您绝对确定 HTML/DOM 结构不会改变,您或许可以使用:

this.nextSibling.children[0];

但这在将 textNode 视为 childNode

的浏览器中可能会出现问题

关于javascript - 将多个内部子节点传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9606279/

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