javascript - svg 中的函数不是通过 html 中的 javascript 调用的
问题描述
我的 HTML 如下所示。mpAddChartValue 函数存在于名为 mpChart.svg 的 svg 文件中。但是当我运行 HTML 页面时,在浏览器控制台中出现“未捕获的 TypeError:window.mpAddChartValue 不是函数”错误。
<!DOCTYPE html>
<html>
<head>
<script language="Javascript">
function mpPopulate()
{
window.mpAddChartValue()
}
</script>
</head>
<body onload="mpPopulate()">
<embed src="mpChart.svg" type="image/svg+xml" width="500" height="290" pluginspage="http://www.adobe.com/svg/viewer/install/"></embed>
</body>
</html>
这里是 SVG 内容
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="mpChart.css" type="text/css"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"
width="100%" height="100%" viewBox="0 0 600 350" xml:space="preserve">
<script type="text/javascript"><![CDATA[
function mpAddChartValue()
{
alert('Test function')
}
]]></script>
mpAddChartValue 在这里仅显示为测试函数。任何帮助将非常感激。提前致谢
解决方案
推荐阅读
- json - 无法从反应表单将数据发布到我的 API
- matplotlib - matplotib 3D 图形显示表面和轮廓以及正确隐藏的部分?
- r - 闪亮的应用程序在本地运行没有问题,但被服务器断开连接
- javascript - 如何将坐标保存到 Firebase
- docker - 为什么我无法连接到 docker 中的 postgres?
- kotlin - 期待 Kotlin 1.3 的顶级声明
- c++ - 如何解决 macOS catalina 上的此错误?
- r - 删除变量的一个值出现一次的 ID
- rust - 在字符串字符 for 循环中使用可变或不可变引用
- amazon-web-services - 您是否需要为访问 AWS Cost Explorer 控制面板付费?