我有一個(gè)按鈕,單擊該按鈕時(shí)要提醒的背景圖片網(wǎng)址#div1??赡軉??
3 回答

波斯汪
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
是的,這是可能的:
$("#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);
});
添加回答
舉報(bào)
0/150
提交
取消