简体   繁体   English

没有收到控制台错误,但是脚本不起作用

[英]Not getting console errors, but script is not working

When I run my "app", I generate SVG code. 当我运行“应用程序”时,会生成SVG代码。

I've scoured the answers here, but am not finding my particular issue. 我在这里搜寻了答案,但是找不到我的特定问题。

I am generating valid SVG syntax with the appropriate xmlns attribute specified. 我正在使用指定的适当xmlns属性生成有效的SVG语法。

I can look at the developer tools in chrome, and the body of my document is generating, its just not displaying. 我可以看一下chrome中的开发人员工具,而我的文档主体正在生成,只是没有显示。

If I copy and paste the generated body into a new html document everything works. 如果我将生成的正文复制并粘贴到新的html文档中,则一切正常。

My code-base is too large (because of the library i have built) to share, but I will share the copy >> paste of the generated body as proof that all is working. 我的代码库太大(因为我已经建立了库),因此无法共享,但是我将共享所生成主体的副本>>粘贴,以证明所有代码都在工作。

 <svg id="can" width="1000px" height="300px" xmlns="http://www.w3.org/2000/svg"> <g id="rowStack"> <g id="M001_header"> <g onclick="eval(&quot;M001_cb.toggleCheck();&quot;);"> <g> <path d="M0 20 0 40 20 20 " stroke-width="0px" stroke="#333" fill="#333"></path> <path d="M20 20 0 40 20 40 " stroke-width="0px" stroke="#888" fill="#888"></path> <path d="M2 22 2 38 18 38 18 22 " stroke-width="0px" stroke="#CCC" fill="#CCC"></path> </g> <path style="display:none" d="M3.055555555555556 32.77777777777778 4.166666666666667 31.38888888888889 8.055555555555555 35 15.555555555555557 22.22222222222222 16.944444444444446 23.055555555555557 8.333333333333334 37.77777777777778 3.055555555555556 32.77777777777778 " stroke="black" stroke-width="0px" fill="black"></path> <path style="display:none" d="M4 24 4 36 16 36 16 24 " stroke="black" stroke-width="0px" fill="black"></path> </g> <text x="25px" y="35px" font-family="arial" font-size="14" stroke="black" fill="black">M001</text> <g id="M001_ex" onclick="expandoToggle('M001_ex')"> <rect x="120px" y="20px" width="72px" height="72px" fill="#aaa"></rect> <path d="M138 53 153 53 153 38 159 38 159 53 174 53 174 59 159 59 159 74 153 74 153 59 138 59 138 53 " stroke-width="0px" stroke="#333" fill="#333"></path> </g> </g> <g id="M002_header"> <g onclick="eval(&quot;M002_cb.toggleCheck();&quot;);"> <g> <path d="M0 40 0 60 20 40 " stroke-width="0px" stroke="#333" fill="#333"></path> <path d="M20 40 0 60 20 60 " stroke-width="0px" stroke="#888" fill="#888"></path> <path d="M2 42 2 58 18 58 18 42 " stroke-width="0px" stroke="#CCC" fill="#CCC"></path> </g> <path style="display:none" d="M3.055555555555556 52.77777777777778 4.166666666666667 51.388888888888886 8.055555555555555 55 15.555555555555557 42.22222222222222 16.944444444444446 43.05555555555556 8.333333333333334 57.77777777777778 3.055555555555556 52.77777777777778 " stroke="black" stroke-width="0px" fill="black"></path> <path style="display:none" d="M4 44 4 56 16 56 16 44 " stroke="black" stroke-width="0px" fill="black"></path> </g> <text x="25px" y="55px" font-family="arial" font-size="14" stroke="black" fill="black">M002</text> <g id="M002_ex" onclick="expandoToggle('M002_ex')"> <rect x="120px" y="40px" width="72px" height="72px" fill="#aaa"></rect> <path d="M138 73 153 73 153 58 159 58 159 73 174 73 174 79 159 79 159 94 153 94 153 79 138 79 138 73 " stroke-width="0px" stroke="#333" fill="#333"></path> </g> </g> </g> </svg> 

My Basic generation of the SVG is found in a pattern consistent with the following: 我的基本SVG代以与以下方式一致的模式找到:

 var svgRect = function(id) { this.id = id; this.x = 0; this.y = 0; this.w = 100; this.h = 20; this.elem; return this; } svgRect.prototype.init = function() { this.elem = document.createElementNS('http://www.w3.org/2000/svg','rect'); this.redraw(); return this; } svgRect.prototype.redraw = function() { this.elem.setAttribute('id',this.id); this.elem.setAttribute('x',this.x); this.elem.setAttribute('y',this.y); this.elem.setAttribute('width',this.w + "px"); this.elem.setAttribute('height',this.h + "px"); this.elem.setAttribute('fill','#888'); this.elem.setAttribute('stroke-width','1px'); this.elem.setAttribute('stroke','#AAA'); return this; } var svg = document.getElementById('can'); var rect1 = new svgRect('rect1').init(); rect1.x = 200; rect1.redraw(); svg.appendChild(rect1.elem); var rect2 = new svgRect('rect2').init(); svg.appendChild(rect2.elem); 
 <svg id="can" width="1000px" height="300px" xmlns="http://www.w3.org/2000/svg"></svg> 

The problem is: My code is not working AND NOT generating errors at the console. 问题是:我的代码不起作用并且在控制台上未生成错误。

I'm getting body generation of the code, and my "app" code is not working. 我正在生成代码的主体,而我的“应用”代码无法正常工作。

The example provided however is working, and this is inconsistent, but I have no reported errors to give me a clue as to why. 但是,提供的示例正在运行,并且不一致,但是我没有报告错误,因此无法提供原因的线索。

This is all running client side (Chrome). 这都是在运行客户端(Chrome)。

Please help. 请帮忙。

I appended the following to my script and it worked, but it is highly likely that it is not the right answer: 我将以下内容附加到脚本中,并且可以正常工作,但是很可能这不是正确的答案:

        var myHTML = svg.innerHTML;
        svg.innerHTML = myHTML;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM