第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在d3中以編程方式調(diào)用“點(diǎn)擊”事件?

如何在d3中以編程方式調(diào)用“點(diǎn)擊”事件?

牧羊人nacy 2019-11-29 11:09:22
我正在嘗試這樣(也在https://gist.github.com/1703994):<!DOCTYPE html><html>  <head>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.27.2"></script>    <script type="text/javascript" src="http://mbostock.github.com/d3/d3.time.js?1.27.2"></script>    <script type="text/javascript" src="js-libs/jquery-1.7.js"></script>    <style>      <!--      #test {      width: 400px;      height: 500px;      }      -->    </style>  </head>  <body>    <script type="text/javascript">      $(function() {        var w = 600,            h = 350;        var vis = d3.select("#test").append("svg:svg")        .attr("width", w)        .attr("height", h)        .append("svg:g")        .attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");        var g = vis.selectAll("g")        .data([ { x:1 , y: 2} ])        .enter().append("svg:g");        g.append("svg:path")        .attr("fill", "red")        .attr("stroke", "red")        .attr("stroke-width", "10")        .attr("d", "M 100 350 l 150 -300")        g.select("path")        .on("click", function() { console.log("Hello"); });        // XXX: how to execute click programmaticaly?      })    </script>    <div id="test"></div>  </body></html>但是不起作用我認(rèn)為我們可以使用https://github.com/mbostock/d3/wiki/Internals#wiki-dispatch_on但是怎么做呢?
查看完整描述

3 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗 獲得超3個贊

只需將.on方法作為注冊值的獲取方法(即您的處理程序函數(shù))進(jìn)行調(diào)用,然后調(diào)用該方法的結(jié)果:


g.select("path").on("click")();

如果您的處理程序使用綁定的數(shù)據(jù)和/或事件字段,或者綁定了多個事件偵聽器(例如,“ click.thing1”和“ click.thing2”),則情況將變得更加復(fù)雜。在這種情況下,最好使用標(biāo)準(zhǔn)的DOM方法觸發(fā)一個偽事件:


var e = document.createEvent('UIEvents');

e.initUIEvent('click', true, true, /* ... */);

g.select("path").node().dispatchEvent(e);


查看完整回答
反對 回復(fù) 2019-11-29
  • 3 回答
  • 0 關(guān)注
  • 967 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號