在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ d3 給元素添加click事件,為何點擊2次才生效?

d3 給元素添加click事件,為何點擊2次才生效?

.point-create 為點
.tipArrow-create為箭頭
`showTipArrow=()=>{

d3.selectAll('.point-create').on('click',function(){//選擇所有的點添加點擊事件
  let $thisDom=d3.select(this);
  d3.selectAll('.tipArrow-create').filter(function(d,i,list){
    let arrowDom=d3.select(this);
    if(arrowDom.attr('regId')==$thisDom.attr('regId')){//匹配點是否跟箭頭的regId一致
      arrowDom.attr('display','');
    
    }
  });
});
}`

點是動態(tài)添加的,showTipArrow函數(shù)位置放在動態(tài)添加點函數(shù)里面,
 d3.select('#points').append('use')
          .attr('id', 'red_'+thisId)
          .attr('regId',thisId)
          .attr('type', 'point')
          .attr('x', width-10)
          .attr('y', cyRed-10)
          .attr('yy',cyRed)
          .attr('class', 'point-create')
          .attr('xlink:href','#point')
          .call(d3.drag()
              .on('start', dragstarted)
              .on('drag', dragged)
              .on('end', dragended));
       this.showTipArrow();       

結(jié)果就是需要點擊2次的時候添加的click函數(shù)才會生效,有人知道怎么回事嗎?

回答
編輯回答
爛人

我把添加的drag事件去掉以后就正常了?

2018年1月15日 02:26