从background-image属性中获取网址 [英] Get just the URL from background-image property
本文介绍了从background-image属性中获取网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何只从background-image属性中获取网址:
现在我这样做:
(window.getComputedStyle(element).getPropertyValue(background-image))。replace('url(','')。replace(')',' ;
但是如果在background-image中还有其他的东西,比如webgradient等等,我会得到他们。
<$>
解决方案
p $ p> var m =(window.getComputedStyle(element).getPropertyValue(background-image))。match(/ url\(([^)] +)\)/ i );
if(m){... m [1] ...}
How can I get just the URL from the background-image property:
Right now I do this:
(window.getComputedStyle(element).getPropertyValue("background-image")).replace('url(','').replace(')','');
But if in the background-image there are other things like webgradient and so, I will get them too. How can I avoid that?
解决方案
What about doing this:
var m = (window.getComputedStyle(element).getPropertyValue("background-image")).match(/url\(([^)]+)\)/i);
if (m) { ... m[1] ... }
这篇关于从background-image属性中获取网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文