Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为ajax重新初始化SVGweb_Svg_Svgweb - Fatal编程技术网

为ajax重新初始化SVGweb

为ajax重新初始化SVGweb,svg,svgweb,Svg,Svgweb,当页面被简单加载(打开)时,使用SVGweb没有问题 如何重新初始化SVGweb以重新绘制页面上的所有SVG 另外,我需要SVGweb重新扫描并重新加载页面上的所有内容 来源(来源): ... 对此(就像SVGweb si在打开页面时所做的那样): ... 我之所以需要它,是因为我使用ajax更改SVG图形,并且需要在页面上重新呈现它。使用新的SVGweb代码更改DOM后(通过ajax) 到 svg.js:查找并删除以下内容: arguments.callee.done=true; 或

当页面被简单加载(打开)时,使用SVGweb没有问题

如何重新初始化SVGweb以重新绘制页面上的所有SVG

另外,我需要SVGweb重新扫描并重新加载页面上的所有内容

来源(来源):


...
对此(就像SVGweb si在打开页面时所做的那样):


...

我之所以需要它,是因为我使用ajax更改SVG图形,并且需要在页面上重新呈现它。

使用新的SVGweb代码更改DOM后(通过ajax)

svg.js:查找并删除以下内容:

arguments.callee.done=true;
或替换为

arguments.callee.done=false;
编辑

IE9还有一个解决方案:

对于svg.js

//清理onDOMContentLoaded处理程序以防止IE上的内存泄漏
var IEv=parseFloat(navigator.appVersion.split(“MSIE”)[1]);

if(IEv我需要相同的功能,并找到了如何在不修改svgweb源代码或手动调用
\onDOMContentLoaded()
处理程序的情况下正确执行此操作的方法。事实上,它是本机支持的

诀窍是使用
window.svgweb.appendChild()
将SVG元素(重新)附加到DOM,这将导致svgweb按原样处理节点

示例,使用jQuery:

// Iterate over all script elements whose type attribute has a value of "image/svg+xml".
jQuery('body').find('script[type="image/svg+xml"]').each(function () {
    // Wrap "this" (script DOM node) in a jQuery object.
    var $this = jQuery(this);
    // Now we use svgweb's appendChild method. The first argument is our new SVG element
    //  we create with jQuery from the inner text of the script element. The second
    //  argument is the parent node we are attaching to -- in this case we want to attach
    //  to the script element's parent, making it a sibling.
    window.svgweb.appendChild(jQuery($this.text())[0], $this.parent()[0]);
    // Now we can remove the script element from the DOM and destroy it.
    $this.remove();
});

为了使其正常工作,我建议使用专用div包装所有SVG脚本标记,以便在附加SVG元素时,将其附加到不包含任何其他节点的父元素。这消除了在此过程中无意中重新排列节点的可能性。

如果更改DOM,它应自动重新命名。Robert:这不是自动完成的…我正在寻找如何手动完成。没有任何机制可以做到这一点。你可能必须进入SVGWeb的源代码并修复潜在的错误。罗伯特:找到了解决方案。谢谢。我已经删除了分散注意力的文本,因为它没有给这个答案增加任何技术价值,因此没有必要。看起来引发了一些讨论;也许你想参与其中:。
    if (arguments.callee.done) {
      return;
    }
    if (arguments.callee.done) {
      //return;
    }
arguments.callee.done=true;
arguments.callee.done=false;
var a=document.getElementById("__ie__svg__onload");if(a){a.parentNode.removeChild(a);a.onreadystatechange=null}
var IEv=parseFloat(navigator.appVersion.split("MSIE")[1]);if(IEv<9){var a=document.getElementById("__ie__svg__onload");if(a){a.parentNode.removeChild(a);a.onreadystatechange=null;a=null;}}
    // cleanup onDOMContentLoaded handler to prevent memory leaks on IE
    var listener = document.getElementById('__ie__svg__onload');
    if (listener) {
      listener.parentNode.removeChild(listener);
      listener.onreadystatechange = null;
      listener = null;
    }
    // cleanup onDOMContentLoaded handler to prevent memory leaks on IE
    var IEv=parseFloat(navigator.appVersion.split("MSIE")[1]);
    if (IEv<9) {
        var listener = document.getElementById('__ie__svg__onload');
        if (listener) {
          listener.parentNode.removeChild(listener);
          listener.onreadystatechange = null;
          listener = null;
        }
    }
// Iterate over all script elements whose type attribute has a value of "image/svg+xml".
jQuery('body').find('script[type="image/svg+xml"]').each(function () {
    // Wrap "this" (script DOM node) in a jQuery object.
    var $this = jQuery(this);
    // Now we use svgweb's appendChild method. The first argument is our new SVG element
    //  we create with jQuery from the inner text of the script element. The second
    //  argument is the parent node we are attaching to -- in this case we want to attach
    //  to the script element's parent, making it a sibling.
    window.svgweb.appendChild(jQuery($this.text())[0], $this.parent()[0]);
    // Now we can remove the script element from the DOM and destroy it.
    $this.remove();
});