【发布时间】:2015-04-03 19:59:00
【问题描述】:
我正在尝试将 onclick 事件添加到 svg 元素。
所以我在下面的特定元素中添加了一个 onclick 属性。但是它似乎不起作用。
我得到以下错误:“Uncaught ReferenceError: clickCounty is not defined”
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function clickCounty(e)
{
console.log("clickCounty");
}
});
</script>
</head>
<body>
<div id="canvas">
<object data="custom.svg" type="image/svg+xml">
</div>
</body>
</html>
custom.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect onclick="clickCounty('test')" x="10" y="10" height="100" width="100" style="stroke:#006600; fill: #00cc00"/>
</svg>
【问题讨论】:
标签: svg