繁体   English   中英

D3使用d3.selectAll()给了我一个语法错误

[英]D3 is giving me a syntax error with d3.selectAll()

我的情况是这样的:我试图从一个类列表中选择一个类,该类以数字开头但类型为字符串(我检查过)。

list_item.on("click", function(){
  var to_find = $(this).text().replace(/\s/g, "_");

  console.log(typeof(to_find)); // on a certain moment this will become "00s"

  sampleSVG.selectAll(".node:not(."+to_find+") circle, .line:not(."+to_find+")")
    .transition()
    .duration(500)
    .style("fill", st_colours.node.fill)
    .style("stroke", function(d){return d.type == "node" ? st_colours.node.stroke : st_colours.line.stroke});

  sampleSVG.selectAll(".node."+to_find+" circle, .line."+to_find)
    .transition()
    .duration(1000)
    .style("fill", st_colours.random(a))
    .style("stroke", d3.rgb(st_colours.random(a)).darker());
});

当“ var to_find”更改为“ 00s”时,出现此错误:

SyntaxError: An invalid or illegal string was specified

谁能告诉我为什么我会收到此错误?

在选择器中,您引用的是名为00s的类:

.node:not(.00s)

根据CSS语法,类名应以下划线,破折号或字母开头。 也许这就是为什么您遇到SyntaxError的原因。

另请参阅: 哪些字符在CSS类名称/选择器中有效?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM