开发者

How to iterate over inputs of certain class with Prototype

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').in开发者_C百科voke(function(e){
      alert(?input value?)
    });

thanks


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.


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'
        });
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜