Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何URL从定义为的元素中获取属性值
URL
<html> <head> <style type="text/css">.sprite-thumb {background-image:url(example.jpg);}</style> </head> </html>
我试过$(data).find("header").css("sprite-thumb")但得到了undefined
$(data).find("header").css("sprite-thumb")
undefined
你可以这样做:
var target = $('.sprite-thumb').css('background-image'), bg = target.replace(/(^(url\()|\)$)/g,"");
它基本上使用.css() jQuery 函数来检索值background-image,然后从中删除url(和删除),只留下 url。
background-image
url(
)
小提琴