What is the best way to cut the file name from 'href' attribute of an 'a' element using jQuery?

后端 未结 6 580
傲寒
傲寒 2021-01-16 19:32

For example I\'ve got the simple code:

6条回答
  •  感动是毒
    2021-01-16 20:15

    use

    lastIndexof and substring

    Give anchor tag an id

    var elem = document.getElementById ( "anch1" );
    
    elem.href.substring (elem.href.lastIndexOf ( '/' ) + 1 );
    

    Using jQuery

    $(function() {
        $("ul.list li a").each ( function() {
            alert ( $(this).attr ( "href" ).substring ($(this).attr ( "href" ).lastIndexOf ( '/' ) + 1 ) )
        });
    });
    

提交回复
热议问题