2016-10-25 209 views
0

我在Inkscape中生成的內聯svg代碼中選擇並操作(我想添加點擊行爲)時出現問題,然後粘貼到我的html文件中。d3選擇和修改svg元素中的g元素

<svg version="1.1" id="layer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
width="905.1372px" height="1100px" viewBox="0 300 721.464 889.561" enable-background="new 0 0 721.464 889.561" 
xml:space="preserve"> 


<g id="section3"> 
<path id="section" 
    d="m 433.125,729.14792 -0.17857,32.67857 32.32143,0.44643 15.89286,-0.44643 11.78571,-3.03572 -11.33928,-35.26785 -19.82143,5.625 z"/> 
</g> 

我已經試過各種方式..的getElementById,d3.select( 「#ID」)......的任何人都可以幫助嗎?

+1

顯示什麼你已經嘗試了實際的代碼。 –

回答

1

通過ID:

d3.select("#section3") 

檢查本演示中,點擊您的路徑上(你必須向下滾動才能找到它):

d3.select("#section3").on("click", function(){ 
 
    console.log("hello"); 
 
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> 
 

 
<svg version="1.1" id="layer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
 
width="905.1372px" height="1100px" viewBox="0 300 721.464 889.561" enable-background="new 0 0 721.464 889.561" 
 
xml:space="preserve"> 
 

 

 
<g id="section3"> 
 
<path id="section" 
 
    d="m 433.125,729.14792 -0.17857,32.67857 32.32143,0.44643 15.89286,-0.44643 11.78571,-3.03572 -11.33928,-35.26785 -19.82143,5.625 z"/> 
 
</g>

+0

非常感謝! – gsol