获取“sections.each 不是函数”使用 javascript / scriptaculous
尝试使用 Scriptaculous 的示例代码进行一些拖放操作。它在 IE8 中工作正常,但 Firefox 和 Chrome 会生成“sections.each is not a function”错误。
这是代码:
function getGroupOrder() {
var sections = document.getElementsByClassName('section');
var alerttext = '';
sections.each(function(section) {
var sectionID = section.id;
var order = Sortable.serialize(sectionID);
var mySectionID = Right(section.id);
var myLen = String(Sortable.sequence(section)).length;
var StuCode = "";
if (myLen ==8)
{var StuCode = String(Sortable.sequence(section)).substring(myLen, 2);}
else if (myLen ==9)
{var StuCode = String(Sortable.sequence(section)).substring(myLen, 3);}
alerttext += mySectionID + ': ' + StuCode + '\n';
alerttextb = sectionID + ': ' + StuCode + '\n';
}
}
论坛上建议的一个解决方案“我能够通过使用 $A() 包装对 document.getElementsByClassName('section'); 的调用来解决此问题”,但我不知道这意味着什么!我问这是什么意思,但这个帖子是2008年发的,至今还没有回复。
Trying an example piece of code for Scriptaculous for doing some drag and drop. It works fine in IE8 but Firefox and Chrome generate an error of 'sections.each is not a function.
Here is the code:
function getGroupOrder() {
var sections = document.getElementsByClassName('section');
var alerttext = '';
sections.each(function(section) {
var sectionID = section.id;
var order = Sortable.serialize(sectionID);
var mySectionID = Right(section.id);
var myLen = String(Sortable.sequence(section)).length;
var StuCode = "";
if (myLen ==8)
{var StuCode = String(Sortable.sequence(section)).substring(myLen, 2);}
else if (myLen ==9)
{var StuCode = String(Sortable.sequence(section)).substring(myLen, 3);}
alerttext += mySectionID + ': ' + StuCode + '\n';
alerttextb = sectionID + ': ' + StuCode + '\n';
}
}
One solution suggested on a forum "I was able to resolve this issue by wrapping the call to document.getElementsByClassName('section'); with $A()" but I don't have a clue what that means! I asked what it meant but the post was made in 2008 and no reply as yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本机实现上的
getElementsByClassName
方法返回一个NodeList
,而不是Array
对象。PrototypeJS 中的
$A
方法可以转换任何可迭代对象转换为 Array 对象,例如:The
getElementsByClassName
method on native implementations returns aNodeList
, not anArray
object.The
$A
method from PrototypeJS to converts any iterable object into anArray
object, for example: