javascript - .on ("drag", function()) 和 .on ("contextmenu", function()) 在同一代码上使用时不起作用

标签 javascript d3.js

这是一个在甘特图中附加 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/

相关文章:

javascript - 保持元素在父元素的底部

javascript - 基于字符出现的 CSS 选择器?

javascript - 如何减少第一个字节的时间

D3.js - 如何在条形图中突出显示最大和最小(最小和最大)列?

javascript - 如何在 Node js中将主机名解析为IP地址

google-maps - 具有大数据的地理热图(google)

javascript - 在javaScript中将文本文件解析为数组中的对象

javascript - d3 等值线队列和填充问​​题

javascript - 如何完全删除 d3 forceSimulation 及其拖动 handle

Javascript xml 解析器 : how to get nodes that have ":" in the name