首页 > 解决方案 > 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 在这里仅显示为测试函数。任何帮助将非常感激。提前致谢

标签: javascriptsvg

解决方案


推荐阅读