[英]How to check if svg has a fill-opacity versus a fill-opacity of 0?
Suppose I want to check the fill-opacity of a SVG element. 假设我要检查SVG元素的填充不透明度。 I'd do this 我会这样做
elem.attr('fill-opacity');
This can give me back 0 if the element has no fill-opacity attribute or if the fill-opacity has been set to 0. 如果该元素没有fill-opacity属性或fill-opacity设置为0,则可以返回0。
How do I distinguish between those two cases? 如何区分这两种情况?
您不能简单地使用elem.hasAttribute吗?
If fill-opacity
is not specified, attr()
returns undefined
. 如果未指定fill-opacity
,则attr()
返回undefined
。
alert("fill-opacity (DOM) ="+document.getElementById("test").getAttribute("fill-opacity")); alert("fill-opacity (jQuery) ="+$("#test").attr("fill-opacity"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <svg> <rect id="test" width="10" height="10"/> </svg>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.