我可以获取div的背景图片网址吗?

我有一个按钮,单击该按钮时要提醒的背景图片网址#div1。


可能吗?


三国纷争
浏览 794回答 3
3回答

波斯汪

是的,这是可能的:$("#id-of-button").click(function() {    var bg_url = $('#div1').css('background-image');    // ^ Either "none" or url("...urlhere..")    bg_url = /^url\((['"]?)(.*)\1\)$/.exec(bg_url);    bg_url = bg_url ? bg_url[2] : ""; // If matched, retrieve url, otherwise ""    alert(bg_url);});
打开App,查看更多内容
随时随地看视频慕课网APP