How to create Hash object/array using jquery?

前端 未结 5 1100
挽巷
挽巷 2021-01-05 18:55

I know there is a Hash() object in the Javascript prototype framework, but is there anything in Jquery like this?

As I would like to stick with one javascript framew

5条回答
  •  失恋的感觉
    2021-01-05 19:38

    There's a standalone hash table implementation called jshashtable (full disclosure: I wrote it). Using it, your code would be:

    var starSaves = new Hashtable();
    
    function myHover(id, pos)
    {
        var starStrip = $('star_strip_' + id);
        if (!starSaves.containsKey(id))
        {
            var starSave = new Array();
            var imgs = starStrip.select("img")
            alert(imgs);
            for (var i = 0; i < imgs.length; i++)
            {
                starSave[starSave.length] = imgs[i].src;
                if (i < pos)
                    imgs[i].src = "/images/star_1.gif";
                else
                    imgs[i].src = "/images/star_0.gif";
    
            }
            starSaves.put(id, starSave);
        }
    }
    

提交回复
热议问题