我正在尝试使用AngularJS和Jquery找到SVG图像的路径ID,但是下面的代码不起作用。有什么建议吗?
var app = angular.module("myApp", []);
app.controller('uiCtrl', function($scope,$http) {
$scope.list1 = {img : 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/gallardo.svg'};
});
document.querySelector('object').addEventListener('load',function(){
var p = this.contentDocument.documentElement.querySelectorAll('path');
for(i=0;i<p.length;i++){
p[i].addEventListener('click', function(){
alert("PATH ID"+this.id+"…")
});
}
});
#previewImg{
border : 1px solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.9/angular.min.js"></script>
<div ng-app="myApp" ng-controller="uiCtrl" >
<object id="previewImg" ng-attr-data="{{list1.img}}" type="image/svg+xml" width=100% height="100%"></object>
</div>