开发者

What does $$('foo') mean in JavaScript source code?

开发者 https://www.devze.com 2023-01-08 18:26 出处:网络
I have the following in javascript: var entriesString = \'\'; $$(\'select[id=shopId]\').each(function(elem, i){

I have the following in javascript:

var entriesString = '';
        $$('select[id=shopId]').each(function(elem, i){
            shops[i] = elem.value;
            entries[i] = new Array();

            $$('input[id=entry'+i+']').each(function(elem, c){
                if(elem.value != '') entries[i][c] 开发者_开发技巧= elem.value.replace(".", "").replace(",", "."); else entries[i][c] = '0.0'
            });
            entriesString += '&entry'+i+'=' + entries[i];
            });

Now I'm new to JS and therefore do not know what the first $$('select[id=shopId]') part means. It must be some sort of array or collection, due to the .each part it is followed by. In that loop is again a nested loop that uses the loop variable i in its head. But again, I don't know what exactly does %%('input[...]') mean. What kind of syntax is this? Also, where does the data.

This is what entryString looks like for example:

&entry0=65.8,75.5,72.9,67.9,51.1,8.2,47.9&entry1=55.9,33.5,33.8,35.2,26.8,7.0,25.8

Thanks a lot or your help!


That looks like the $$ method of the Prototype library. The documentation is here:

http://www.prototypejs.org/api/utility#method-$$

It selects DOM elements given a CSS-style selector.


$$() is not something of javascript. It seems to be likely that you're using the Prototype Javascript Framework. Here you find the documentation of $$: http://api.prototypejs.org/language/dollardollar/


You are using the Prototype library.

See http://www.prototypejs.org/api/utility/dollar-dollar


your code uses the prototype JS framework. $$('ELEMENTNAME') instanciates all DOM element with ELEMENTNAME (so i.e. all input fields) and returns them as array of objects.

with id==xy it returns that one with id xy

<input type="blah" id="xy" value="123" />

will be found


It use a great function to get elements with css selectors.

0

精彩评论

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

关注公众号