如何使用 Prototype 迭代特定类的输入

发布于 2024-08-28 17:21:26 字数 172 浏览 1 评论 0原文

我想迭代属于某个类(例如“required”)的输入数组。我怎样才能遍历它并获取它们的值? 一样的东西

$$('input required').invoke(function(e){
      alert(?input value?)
    });

像谢谢

I want to iterate over an array of inputs that belong to certain class (eg."required"). How can I traverse it and get their values ? Something like

$('input required').invoke(function(e){
      alert(?input value?)
    });

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抽个烟儿 2024-09-04 17:21:26

您已经很接近了:

$('input.required').each(function(i){
    console.log($F(i));
});

所有具有 required 类的输入都将被迭代,并且它们的值将显示到 Firefox 控制台。如果您不使用 Firefox,只需将 console.log 更改为 alert 即可查看结果。

You're close:

$('input.required').each(function(i){
    console.log($F(i));
});

All inputs with the class of required will be iterated through and their value displayed to the Firefox console. If you don't use Firefox just change console.log to alert to see the results.

-小熊_ 2024-09-04 17:21:26

这对我有用。

示例代码:

document.observe("dom:loaded", function() {
    var maxHeight = 0;

    $('.product-name').each(function(i){

        var eleHeight = i.getHeight();

        if (eleHeight > maxHeight){
            maxHeight = eleHeight;
        }
    });

    $('.product-name').each(function(i){
        i.setStyle({
            height: maxHeight+'px'
        });
    });
});

It works me.

example code:

document.observe("dom:loaded", function() {
    var maxHeight = 0;

    $('.product-name').each(function(i){

        var eleHeight = i.getHeight();

        if (eleHeight > maxHeight){
            maxHeight = eleHeight;
        }
    });

    $('.product-name').each(function(i){
        i.setStyle({
            height: maxHeight+'px'
        });
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文