Javascript Raphael.js属性和VML
对于Raphael,我想创建一个具有Id属性的矩形,如下例所示Javascript Raphael.js属性和VML,javascript,attributes,svg,raphael,vml,Javascript,Attributes,Svg,Raphael,Vml,对于Raphael,我想创建一个具有Id属性的矩形,如下例所示 <rect id="aRect" x="10" y="10" width="50" height="50" r="2" rx="2" ry="2"/> 并使用如下代码设置Id var elem = _paper.rect(10, 10, 50, 50, 2); elem[0].setAttributeNS(null, 'id', 'aRect'); elem.node.id = 'aRect'; 或者使用这样的代
<rect id="aRect" x="10" y="10" width="50" height="50" r="2" rx="2" ry="2"/>
并使用如下代码设置Id
var elem = _paper.rect(10, 10, 50, 50, 2);
elem[0].setAttributeNS(null, 'id', 'aRect');
elem.node.id = 'aRect';
或者使用这样的代码
var elem = _paper.rect(10, 10, 50, 50, 2);
elem[0].setAttributeNS(null, 'id', 'aRect');
elem.node.id = 'aRect';
现在raphael回到了旧IE右侧的vml,我如何添加一个id属性来满足vml的情况,或者该代码是否也适用于该情况?在阅读MS页面后,我实现了这个设置id的解决方案
function setId(el, id){
if(el === null || typeof el !== 'object') return;
if(Raphael.type === 'SVG') {
el[0].setAttributeNS(null, 'id', id);
}
else if(Raphael.type === 'VML') {
el[0].id = id;
}
}