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

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

For example I\'ve got the simple code:

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-16 20:35

    var myFilename = [];
    $("ul.list li a").each(function() {
          var href = $(this).attr('href'); 
          var idx = $(this).attr('href').lastIndexOf('/');
          myFilename.push((idx >= 0) ? href.substring(idx+1) : href);
    });
    

提交回复
热议问题