在 <textarea> <foreignObject> Chrome 中按预期在句柄内,但不是 Firefox



我正在SVG中的foreignObject中创建一个文本区域,如下所示:

var doc = document.getElementById("cover");
var foreign = document.createElementNS(svgNS,"foreignObject");
var textarea = document.createElementNS("http://www.w3.org/1999/xhtml","textarea");
foreign.setAttributeNS(null,"x",40);
foreign.setAttributeNS(null,"y",40);
foreign.setAttributeNS(null,"width",500);
foreign.setAttributeNS(null,"height",200);
doc.appendChild(foreign);
textarea.setAttributeNS(null,"xmlns","http://www.w3.org/2000/xmlns/");
textarea.textContent = "Text goes here.";
foreign.appendChild(textarea);

这在Chrome中运行良好。然而,在Firefox中,我根本看不到文本区域。当我检查Firebug时,它确实存在,但firefox强制对其进行静态定位,根据我滚动的方式,悬停在html选项卡中对象上的突出显示框甚至不一定在svg内。即使是这样,我也看不到文本区域。我该怎么做才能在Firefox中修复此问题?作为参考,我使用这两种浏览器的最新版本(几个小时前更新(。

如果我更改这一行,对我有效:

textarea.setAttributeNS(null,"xmlns","http://www.w3.org/2000/xmlns/");

对此:

textarea.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/xmlns/");

我认为Firefox只是对名称空间更加严格。这可能是一个错误,但这表明需要http://www.w3.org/2000/xmlns/进行DOM处理是可以接受的:

前缀xmlns:被指定为用于声明命名空间,但其本身与1999年1月的命名空间规范。但是在一些处理上下文中,例如DOM,将所有XML属性表示为(名称空间名称、本地名称(对。为此,命名空间名称分配CCD_ 3。

最新更新