我可以通过以下方式获取背景图像
$('#item').css('background-image').
但结果是url('www.example.com/something/123.png')
如何仅获取123的值? 我不能使用字符串位置,因为图像名称的值不一定是3个字符。
我可以通过以下方式获取背景图像
$('#item').css('background-image').
但结果是url('www.example.com/something/123.png')
如何仅获取123的值? 我不能使用字符串位置,因为图像名称的值不一定是3个字符。
lastIndexOf
和 substring
:var uri= $('#item').css('background-image');
var lastslashindex = uri.lastIndexOf('/');
var result= uri.substring(lastslashindex + 1).replace(".png","");
或者使用.split()
和.pop()
var uri= $('#item').css('background-image');
var result=uri.split("/").pop().replace(".png","");