使用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>
...谢谢
答案 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>