svg无法加载外部js

发布网友

我来回答

1个回答

热心网友

<svg width="580" height="399.9999999"
     xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
     xmlns:ev="http://www.w3.org/2001/xml-events">
<script type="application/ecmascript" xlink:href="demo.js"/>

demo.js

//demo.js 删除<script></script>

我自己写了一个

文件:a.svg

<svg width="100%" height="100%" viewBox="0 0 100 100" version="1.2" baseProfile="full"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/2000/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">
<script type="application/ecmascript" href="s.es"/> 
<circle cx="50" cy="50" r="45" fill="green" onclick="change(evt)" />
</svg>

文件:s.es

function change(evt) {
  if (evt.target.getAttribute('fill') === 'green') {
    evt.target.setAttribute('fill', 'red')
  } else {
    evt.target.setAttribute('fill', 'green')
  }
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com