我正在尝试在使用javascript动态创建的SVG中创建一个简单文本输入数组。
首先我是用PHP做的,其中的代码段如下:
for ($row=0; $row<7; $row++)
{
for ($col=0; $col<7; $col++)
{
$fx=130+100*$col;
$fy=120+100*$row;
echo "<foreignObject x="".$fx."" y="".$fy."" width="50" height="80">\n<body xmlns="http://www.w3.org/1999/xhtml">\n<form><input type="text" width="1"/ style="font-size:48px; border:none;"></form>\n</body>\n</foreignObject>";
}
}
然后在javascript中我会尝试这样的单个实例,但我没有让它工作。
var field = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
field.setAttribute("x", "130");
field.setAttribute("y", "120");
field.setAttribute("width", "50");
field.setAttribute("height", "80");
mySvg.appendChild(field.cloneNode(true));
var s = '<body xmlns="http://www.w3.org/1999/xhtml"><form><input type="text" width="1" style="font-size:48px; border:none;"></form></body>';
var s1 = document.createElement(s);
field.appendChild(s1);
</script>
任何提示?或者我应该切换到完全不同的实现(例如CSS)?