I'd like to split an image's href tag like
&l开发者_JAVA技巧t;img src='/root/myimages/myPic.jpg'>
so that I'm getting just myPic.jpg
- what's the easiest way?
var src = document.getElementById("yourImgId").src;
src = src.replace(/(.*\/)?([^/]*)$/, "$2");
<img id="myImg" src='/root/myimages/myPic.jpg'>
var str = $('#myImg').attr('src');
var newStr = str.substring(str.lastIndexOf("/") + 1);
var t = imageNode.src;
t = (t = t.split('/'))[t.length - 1];
function getFileName(path) {
return path.match(/[-_\w]+[.][\w]+$/i)[0];
}
getFileName('http://www.example.com/images/blah.png'); // blah.png
This getFileName()
function is awesome because the first part of the regex looks like a guy with an eye patch.
精彩评论