(使用http://code.google.com/p/svgweb/)獲得SVG元素 'id' 屬性動態(谷歌SVG網頁)
window.onsvgload = function() {
function onEnter(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
alert(targ.hasAttributeNS(null, 'id')); //displays false
alert(targ.getAttributeNS(null, 'id')); //displays a blank dialog
alert(targ.id); //displays a blank dialog
}
/* Seldom_Seen is a group element in the SVG - <g id="Seldom_Seen">... */
document.getElementById('Seldom_Seen').addEventListener("mouseover", onEnter, false); //alert is blank
document.getElementById('normal_dom_element').addEventListener("mouseover", onEnter, false); //alert displays id as expected
}
事件監聽SVG元素的作品。我似乎無法得到身份證。我可以獲得其他對象屬性,如x,y值。無論如何獲得目標元素的ID?
這工作:e.currentTarget.id 謝謝! – Chris 2010-07-06 15:01:54