javascript:未捕获的TypeError:无法读取属性' get'未定义的

时间:2014-07-14 09:40:32

标签: html5

我是编程新手。我正在使用kineticjs.while使用' get'用于设置所需图层的不透明度的属性。我被这个错误抓住了。

squareShapesLastRow2.on('click', function ()
            {
                var highlightspots=[31,14,20,1,33,16,24,5,10,23,8,30,11,36,13,27];
                a=this;
                indexval = highlightspots.indexOf(parseInt(a.attrs.id));
                console.log(indexval);
                for (var i=0;i<(1+1);i++)
                {
                    if(indexval>=highlightspots.length)
                    {
                    indexval=0;
                    }
                    indexval++;
                }
                    for (var j=0;j<(4+1);j++)
                    {
                        if(indexval<0)
                        {
                            indexval=highlightspots.length-1;
                        }
                        else if(indexval>=0)
                        {
                            var shape = a.highlight_layer.get(highlightspots[indexval])[0];
                            shape.setOpacity(1);
                        }
                        a.highlight_layer.draw();
                        indexval--;
                    }
                setTimeout(function() {
                for (var i = 0; i < highlightspots.length; i++)
                {
                    var shape = a.highlight_layer.get("#high_" + highlightspots[indexval])[0];
                    shape.setOpacity(.3);
                }
                a.highlight_layer.draw();},1000);
            });

1 个答案:

答案 0 :(得分:0)

你应该添加&#39; id&#39;供上述层参考。 代码重写为:   var shape = a.highlight_layer.get(&#34;#&#34; + highlightspots [indexval])[0];