原型数组中的未定义变量 [英] Undefined variable in array in prototype

查看:54
本文介绍了原型数组中的未定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<ul id="litemsd">
 <li class="litemd">
  <input type="checkbox" id="d1" name="d1" />
  <label for="d1">Number One</label>
 </li>
 <li class="litemd">
  <input type="checkbox" id="d2" name="d2" />
  <label for="d2">Numer Two</label>
 </li>
 <li class="litemd">
  <input type="checkbox" id="d3" name="d3" />
  <label for="d3">Numer Three</label>
 </li>
</ul>

在表单的提交观察函数中,我尝试遍历选定的复选框:

And inside the form's submit observe function I try to iterate over the selected checkboxes:

$$('li.litemd').pluck('checked').each(function(s) {
  alert(s.next().innerHTML)
});

但是当到达该代码时,firebug 中会弹出以下错误:

But whe that code is reached, the following error pops up in firebug:

"s is undefined"

有什么提示吗?

推荐答案

我认为您将 pluck() 处理的属性与 HTML 属性混淆了.无论如何,将伪类添加为初始选择器的一部分会更容易,例如:

I think you're confusing the properties which pluck() works on with HTML attributes. It's anyway easier to add the pseudo class of checked as part of the initial selector, like:

$$('li.litemd input:checked').each(function(s) {
      alert(s.next().innerHTML);
  });

示例

这篇关于原型数组中的未定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆