[英]Cannot read property 'nodeName' of undefined in SVG file
That error is generally caused by a script executed before the end of the loading of the page as explain here : Cannot read property childNodes of null 该错误通常是由页面加载结束之前执行的脚本引起的,如此处所述: 无法读取null的属性childNodes
But I don't think that it's my error here : 但是我不认为这是我的错误:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg onload="init(evt)" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<script xlink:href="jquery-1.10.2.min.js"/>
<script xlink:href="test.js"/>
<g id="id">
</g>
</svg>
And the test.js file : 还有test.js文件:
function init () {
$(document).mousedown(test)
}
function test (evt) {
$('#id').append('test');
$('#id').append('<rect x=10 y=10 width=50 height=50/>');
}
What is curious is that the first appending works but not the second one. 令人好奇的是,第一个追加有效,但第二个无效。 Actually the error is raise when there is an
<
in the string... So why ? 实际上,当字符串中有一个
<
时,错误就会引发。那为什么呢?
If you instantiate the element via the jQuery $('<tag_name/>')
method, it works. 如果通过jQuery
$('<tag_name/>')
方法实例化该元素,则它可以工作。
function test (evt) {
$('#id').append('test');
$('#id').append($('<rect/>').attr({'x':10,'y':10,'width':50,'height':50}));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.