此时元素svg上不允许使用属性数据。如何纠正它

时间:2014-09-25 09:12:05

标签: html5 svg w3c w3c-validation svg-animate

使用w3cvalidator检查我的网站时

它显示此错误此时svg元素上不允许的属性数据结束标记svg与当前打开元素的名称(使用)不匹配。

这是我使用的示例代码。

<svg class="ls-l" style="top:320px;left:30%;white-space: nowrap;" 
    data-ls="offsetxin:-15; offsetyin:10; delayin:6854; offsetxout:-15; offsetyout:10; durationout:500; showuntil:1000; easingout:easeInOutQuart; scalexin:0; scaleyin:0; scalexout:0; scaleyout:0;" 
    width="50" height="50" viewBox="0 0 64 64" >
    <use xlink:href="#location-pin">
</svg>

...谢谢

2 个答案:

答案 0 :(得分:1)

data-attributes对于svg并不严格有效,你可以使用getAttribute和setAttribute来设置它们,但是html data attribute API不可用,因此警告。

通常的XML方法是声明自定义命名空间,然后在该命名空间中具有该属性,例如拥有xmlns:ls="<something appropriate for you>"ls:<something>="offsetxin...",然后使用getAttributeNS

访问数据

<use>问题是您没有关闭<use>标记。您需要将其写为<use/><use></use>

答案 1 :(得分:-1)

立即检查。您正在使用:而不是=来为svg元素

的属性指定值
<svg class="ls-l" style="top:320px;left:30%;white-space: nowrap;" 
    data-ls="offsetxin:-15" offsetyin=10 delayin=6854 offsetxout="-15" offsetyout="10" durationout="500" showuntil="1000" easingout="easeInOutQuart" scalexin=0 scaleyin=0 scalexou=0 scaleyout=0 
    width="50" height="50" viewBox="0 0 64 64" >
    <use xlink:href="#location-pin">
</svg>