在ASP.NET页面中内联编码SVG会导致SVG javascript创建SVGPoint();功能中断
我需要在我创建的SVG中使用ASP.NET服务器端代码。为了实现这一点,我创建了一个.aspx文件并插入了如下SVG代码:在ASP.NET页面中内联编码SVG会导致SVG javascript创建SVGPoint();功能中断,javascript,asp.net,svg,Javascript,Asp.net,Svg,我需要在我创建的SVG中使用ASP.NET服务器端代码。为了实现这一点,我创建了一个.aspx文件并插入了如下SVG代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs" Inherits="MyApp.MyPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs"
Inherits="MyApp.MyPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="700px" height="700px" onload="initialize()">
<script type="text/ecmascript">
<![CDATA[
SCRIPT HERE
<% SERVER CODE %>
]]>
</script>
<defs>
<style type="text/css">
<![CDATA[
SVG STYLES
]]>
</style>
</defs>
SVG CODE
<% SERVER CODE %>
</svg>
如果SVG包装在HTML页面中,那么将JS嵌入HTML而不是SVG可能更有意义。给你的SVG元素一个ID,这样你就可以很容易地访问它了。脚本编写完全相同
尽管我怀疑createSVGPoint的有用性,但您最好使用自己的Point原型。如果HTML文档破坏了SVG名称空间,请使用or元素将SVG作为XHTML文档的外部实体加载。我将对此进行测试。就createSVGPoint而言,我可以不使用它。但是,我编写了一个巨大的脚本,它反复利用createSVGPoint。。。虽然不是很理想,但我可以修改它。我更改了JS,使它位于HTML头部。createSVGPoint函数仍然中断。你能发布一个代码片段吗?你怎么称呼它?嗨,请看我的编辑。我添加了一个人为的例子来说明我的问题。createSVGPoint是SVGSVGElement的方法。用
document.getElementById('mySVG')
替换svgRoot如果将SVG作为外部实体加载,如何在其中使用服务器端代码?现在我的SVG充满了。请使用扩展名为.aspx的工作SVG文件作为对象标记的数据值,但将其codetype属性设置为。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<script type="text/ecmascript" language="ecmascript">
var root;
var svgRoot;
var xmlns = "http://www.w3.org/2000/svg";
var mousePoint;
var transformedPoint;
function initialize() {
root = document;
svgRoot = document.documentElement;
//alert("hello"); --Works
mousePoint = svgRoot.createSVGPoint();
transformedPoint = svgRoot.createSVGPoint();
alert("hello"); -- Broken
}
</script>
<style type="text/css">
.Interactable
{
cursor:pointer;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<svg id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="700px" height="700px" onload="initialize()">
<g id="WorkSpace" transform="matrix(1, 0, 0, -1, 350, 350)">
</g>
</svg>
</div>
</form>
</body>
</html>
Response.ContentType = "image/svg+xml";
Response.ContentType = "application/xhtml+xml";