我有一个在html代码中操纵SVG文件(对象)的挑战。 Snap,Raphael有解决方案,但我需要直接通过JavaScript或JQuery来完成。这是我到目前为止有:通过JavaScript或JQuery处理SVG文件(对象)中的元素
JS:
<object id="testSVG" data="image_library/grandstaff_drawing_only.svg"
type="image/svg+xml" height=100% width=100%">
<img src="image_library/alto-clef.png" />
</object>
<script>
window.onload=function() {
// Get the Object by ID
var a = document.getElementById("testSVG");
// Get the SVG document inside the Object tag
var svgDoc = a.contentDocument;
// Get one of the SVG items by ID;
var svgItem = svgDoc.getElementById("path3380");
// Set the colour to something else
//svgItem.setAttribute("stroke", "red");
svgItem.style.stroke = "#ff0000";
};
</script>
JQuery的:
<object id="testSVG" data="image_library/grandstaff_drawing_only.svg"
type="image/svg+xml" height=100% width=100%">
<img src="image_library/alto-clef.png" />
</object>
<script>
window.onload=function() {
var svgDoc = $(“#testSVG”)[0].contentDocument;
$(“#path3380”, svgDoc).css(“stroke”, “red”);
};
</script>
谢谢!
你的问题是什么? –