gpt4 book ai didi

javascript - Coffeescript/Javascript 循环未执行

转载 作者:行者123 更新时间:2023-11-28 00:43:29 24 4
gpt4 key购买 nike

我有一个简单的 CoffeeScript 来处理特定的选择器(part_ids)..

 alert "Starting  blines  " + $("[id*=part_id]").length
for bl in $("[id*=part_id]")
do(bl) ->
procBl bl

procBl = (bl) ->
alert "# of children " + bl.children().length

第一个警报显示页面上有 2 项。For 循环运行——但是 procBl 不会打印警报(它会悄悄退出)看来正在迭代并传递给函数的 bl 不是正确的对象,我无法弄清楚它是什么并且这段代码有问题 -

感谢任何帮助

最佳答案

传递给 procBl 函数的

bl 不是 jQuery 实例,而是普通的 DOM 元素。用 $() 包裹它以使用 children 方法:

  procBl  = (bl)  ->
alert "# of children " + $(bl).children().length

...或使用 $.fn.each 方法迭代 $("[id*=part_id]") 集合。

关于javascript - Coffeescript/Javascript 循环未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27677080/

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