Javascript 第 39 行第 26 列的错误:未定义脚本上 href 的命名空间前缀 xlink
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3561270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error on line 39 at column 26: Namespace prefix xlink for href on script is not defined
提问by l--''''''---------''''''''''''
i am embedding a javascript file inside an svg file like this:
我在 svg 文件中嵌入了一个 javascript 文件,如下所示:
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="958.69"
height="592.78998"
id="svg2275"
sodipodi:version="0.32"
inkscape:version="0.46"
sodipodi:docname="Map of USA with state names.svg"
sodipodi:docbase="C:\temp\webdesign"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<metadata
id="metadata2625">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs2623">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 296.39499 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="958.69 : 296.39499 : 1"
inkscape:persp3d-origin="479.345 : 197.59666 : 1"
id="perspective364" />
</defs>
<script type="text/ecmascript" xlink:href="script.js" />
...
.........
.....
......
and i am getting the above error. anyone know what am idoing wrong?
我收到了上述错误。有谁知道我做错了什么?
回答by speshak
You never defined the xlink namespace (just like the error tells you)
您从未定义过 xlink 命名空间(就像错误告诉您的那样)
You'll need to do something like what was done for the sodipodi namespace:
您需要执行类似于为 sodipodi 命名空间所做的操作:
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
According to the W3C, the appropriate namespace declaration is:
根据 W3C,适当的命名空间声明是:
xmlns:xlink="http://www.w3.org/1999/xlink"
Add that to your root element.
将其添加到您的根元素。
回答by mwittrock
You need to associate the xlinkprefix with a namespace. Try adding the following to your svgelement:
您需要将xlink前缀与命名空间相关联。尝试将以下内容添加到您的svg元素中:
xmlns:xlink="http://www.w3.org/1999/xlink"

