請是有可能的方式,我可以直接從文件本身,例如得到一個SVG文件的文件名,我有這樣的文件夾和文件如何使用JavaScript或檢索從自己SVG文件名或路徑的jQuery
+mainFolder/ <!--Main Folder-->
+svgImgs/ <!--SVG image Folder-->
+image.svg <!--SVG image-->
+index.php <!--index page of Main Folder-->
然後在我的索引頁中,我有這個ajax()
調用,它檢索並附加image.svg
文件。
$.get('svgImgs/image.svg', null, function(data){
var svgNode = $('svg', data);
var docNode = document.adoptNode(svgNode[0]);
$('div').append(docNode);
}, 'xml');
現在的問題是,我想,因爲我對他們有多個觸發事件onclick
爲svg
文件。我想通過SVG文件名或SVG路徑作爲參數
<svg>
<script>
$('svg').on('load', function(){
fileName = //get the file name or file path
$(this).attr('onclick', 'myFunction('+fileName+')');
})
</script>
</svg>
所以我可以在我的索引文件
function myFunction(svg){
//functions here
}
運行myFunction()
請我如何能做到這一點任何更好的建議?