这是html:
<a href="http://site.com/any/different/folders/picture_name.jpg">Go and win</a>
<a href="http://site.com/not/similar/links/some_other_name.png">Go and win</a>
Run Code Online (Sandbox Code Playgroud)
如何从中删除所有数据a href,除了picture_name.jpg?可以有任何长度的链接,我们必须从最后/到最后的值"
而有人不知道要比较,如果最短的方式alt和title流通环节的相等?
谢谢.
如果你想分别实际更改hrefto picture_name.jpg和some_other_name.png,你可以传递一个函数.attr()并使用.lastIndexOf()/ .substring(),如下所示:
$("a").attr('href', function(i, href) {
return href.substring(href.lastIndexOf('/') + 1);
});
Run Code Online (Sandbox Code Playgroud)
或者,如果你正在使用a,.each()你可以获得/使用这样的值:
$("a").each(function() {
var new_href = this.href.substring(this.href.lastIndexOf('/') + 1);
//use it, e.g.: alert(new_href);
});?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
678 次 |
| 最近记录: |