Javascript 为什么getAttributeNS返回null?
Javascript 为什么getAttributeNS返回null?,javascript,svg,Javascript,Svg,var svg=document.getElementById('test'), use=svg.lastElementChild; 警报(使用.getAttributeNS(null,'x')); // "200" 警报(使用.getAttributeNS('s)http://www.w3.org/1999/xlink“,”href'); //“#形状” 警报(使用.getAttributeNS('s)http://foo.io/bar","foo"),; //空-为什么? 查看MDN页面,h
var svg=document.getElementById('test'),
use=svg.lastElementChild;
警报(使用.getAttributeNS(null,'x'));
// "200"
警报(使用.getAttributeNS('s)http://www.w3.org/1999/xlink“,”href');
//“#形状”
警报(使用.getAttributeNS('s)http://foo.io/bar","foo"),;
//空-为什么?
查看MDN页面,html5文档中似乎不支持名称空间-
看起来您必须使用
use.getAttribute('test:foo')代码>谢谢。在示例部分,我完全忽略了这一点。我想我被甩了,因为它为特定的名称空间工作(即http://www.w3.org/1999/xlink
)