2016-07-23 44 views
0

我有一個HTML SVG文件,我想前面的路該文件就像SVG文件,我想隱蔽的JavaScript甲

data:[-23.978,2.474,0,-18.691,2.474,0,-16.108,2.595,0,-14.207,2.866,0,-12.443,3.292,0,-11.003,3.793,0,-9.653,4.413,0,-8.741,4.929,0,-7.869,5.506,0,-6.341,6.686,0,-5.837] 

像這上面的格式,請幫助我。

回答

0

你需要這樣嗎?

var x = document.getElementsByTagName("polygon")[0].getAttribute("points"); 
 

 

 
var x = document.getElementsByTagName("path")[0].getAttribute("d"); 
 
var obj = {}; 
 
obj['data'] = x.split(' '); 
 
console.log(obj);
<svg width="300" height="200"> 
 
    <polygon points="100,10 40,198 190,78 10,78 160,198" 
 
    style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" /> 
 
</svg> 
 

 
    <svg widht:"100" height:"100"> 
 
<path d="M10 10 H 90 V 90 H 10 L 10 10"/> 
 
</svg>

+0

感謝rejs給我你的答案。但不是這種格式我想要svg文件是在JavaScript數據上創建:[ - 23.978,2.474,0,-18.691,2.474,0,-16.108,2.595,0,-14.207]像這樣的格式 –

+0

它是否適用於你呢? –

+0

Dhananjay 4Fox,請參閱最新的答案 –