这是一个在甘特图中附加 svg 的函数。 .on("drag") 是允许 svg 在甘特图中移动。 .on("contextmenu", remove) 调用一个删除 svg 的函数。但这不起作用。它显示错误 Unexpected token 。在 .on("contextmenu") 行中。我可以不在同一代码中使用 .on("drag") 和 .on("contextmenu") 吗?这里出了什么问题?
var bodySelection = d3.select(".chart");
var circleSelection = bodySelection.append("rect")
.attr("x", this.x_start)
.attr("y", this.y_stage)
.attr("width", this.pt)
.attr("height", 25)
.attr("id",this.gantchart_id)
.style("fill", this.color)
.call(drag);
.on("contextmenu", remove)
gantchart[gc_order].id = this.gantchart_id;
gantchart[gc_order].start_point = (this.x_start-80)/5;
gantchart[gc_order].processing_time = this.pt/5;
index = index+1;
gantchart.push({id: "g00", start_point: 0, next_stage: 0, index});
gc_order = gc_order+1;
最佳答案
更改:
.style("fill", this.color)
.call(drag);
.on("contextmenu", remove)
致:
.style("fill", this.color)
.call(drag)
.on("contextmenu", remove)
删除分号。以供将来引用,
Unexpected token
始终是语法错误。一旦修复了语法,错误就会消失。
关于javascript - .on ("drag", function()) 和 .on ("contextmenu", function()) 在同一代码上使用时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34956954/