代码之家  ›  专栏  ›  技术社区  ›  Jack Roscoe

使用javascript创建svg形状

  •  0
  • Jack Roscoe  · 技术社区  · 14 年前

    我已经阅读了与使用javascript创建svg相关的其他问题,并遵循了所有链接,但是我似乎无法让它正常工作。也许这里有人能发现我做错了什么。

    编辑:我目前在文档主体中有一个id为'svgbasics'的div,我正在尝试使用从xml文档中检索到的值创建一个svg形状。

    当我加载页面时,没有显示任何内容。

    这是我的代码:

                          var questions = [];
                      for (j=0; j<arrayIds.length; j++)
                      { 
                        $(xml).find("C[ID='" + arrayIds[j] + "']").each(function(){
                            // pass values
                            questions[j] = 
                            {
                                typ: $(this).attr('typ'),
                                width: $(this).find("I").attr('wid'),
                                height: $(this).find("I").attr('hei'),
                                x: $(this).find("I").attr('x'),
                                y: $(this).find("I").attr('x'),
                                baC: $(this).find("I").attr('baC'),
                                boC: $(this).find("I").attr('boC'),
                                boW: $(this).find("I").attr('boW')
                            }
    
    
                            if ($(this).attr('typ') == '3')
                            {
                                  var shape = this.id;
                                  var svg = $('#svgbasics').svg('get');
    
                                  svg.rect(x($(this).find("I").attr('x')),
                                  y($(this).find("I").attr('y')),
                                  width($(this).find("I").attr('width')),
                                  height($(this).find("I").attr('height')),
                                  {fill: colours[$(this).find("I").attr('baC')]});
    
                            } else {
                                // Add here
                                alert($(this).find("I").attr('x'));
                            }
                        });
                      }
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Erik Dahlström    14 年前

    如果没有完整的背景,很难说出什么是错的。我建议首先在dom/js调试器中检查您的内容,例如 Opera Dragonfly ,WebKit Web Inspector或Mozilla Firebug。验证您的所有元素都已正确创建,并且看起来像您在dom树中所期望的那样。