使用 mootools 多次替换元素名称
moo 中是否有任何等效项可以替换多个元素 id 名称
我有这个
$$('myelement').each(function(el){
var get_all_labels = el.getElements('label');/
var get_label_id = get_all_labels.getProperty('id');
el.addClass(get_label_id);
});
,但 mu 标签 (labael_name) 返回附加后缀,例如 -elem,, 并且我需要删除 <来自新创建的父类名称的strong>-elem,,。我测试了替换,但可能在错误的位置,它返回replace is not a function,还测试了js的自定义string_replace,但我没有任何运气,请任何提示。谢谢!
is there any equivalent in moo that can replace multiple element id names
i have this
$('myelement').each(function(el){
var get_all_labels = el.getElements('label');/
var get_label_id = get_all_labels.getProperty('id');
el.addClass(get_label_id);
});
but mu labels (labael_name) return additional suffix like -elem,, and I need to remove -elem,, from the new created parent class name . I tested replace but probably in the wrong spot , it returns replace is not a function , also tested custom string_replace for js but im not having any luck with it , please any hint. Thnx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点错误。
var get_all_labels = el.getElements('label');
- 返回一个集合var get_label_id = get_all_labels.getProperty('id');
- 返回 ids 数组。因此,如果您有一个标签,它将:
[labelObject#someid-elem]
然后返回["someid-elem"]
问题是,
element.addClass
需要单个字符串,而不是字符串数组,但您可以使用 array.join 来解决这个问题。如果你确实有超过 1 个标签并且需要将它们全部作为类添加到你正在循环的 el 中,你可以这样做,
如果这不是预期的行为并且你实际上只有一个标签,那么就这样做
this is somewhat wrong.
var get_all_labels = el.getElements('label');
- returns a collectionvar get_label_id = get_all_labels.getProperty('id');
- returns an array of ids.so if you have a single label, it will go:
[labelObject#someid-elem]
which will then return["someid-elem"]
the problem is,
element.addClass
requires a single string, not an array of strings but you can use array.join to work around that.if you do have more than 1 label and need to add all of them as classes to the el you are looping, you can do
if this is not the intended behavior and you actually have a single label, then just do