gpt4 book ai didi

jQuery:获取对象的第n个位置

转载 作者:行者123 更新时间:2023-12-01 01:11:19 27 4
gpt4 key购买 nike

我有一个包含复选框的 div。我还有一个接受 jquery 对象参数的函数。它看起来像这样:

function analyze_checkbox(cb) { ... }

鉴于此,是否有一种直接的方法可以知道 cb 参数的子位置?我在想这样的事情:

cb.parent().index(cb)

正确的做法是什么?

谢谢

埃尔文

最佳答案

引用自.index()

If no argument is passed to the.index() method, the return value isan integer indicating the position ofthe first element within the jQueryobject relative to its siblingelements.

所以在你的情况下 cb.index(); 应该这样做

示例位于 http://www.jsfiddle.net/qQzte/

并且不要忘记结果是从 0 开始的

关于jQuery:获取对象的第n个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3921940/

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