从url中删除最后一个元素 [英] Remove last element from url
本文介绍了从url中删除最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从一个范围中删除网址的最后一部分..
I need to remove the last part of the url from a span..
我有
<span st_url="http://localhost:8888/careers/php-web-developer-2"
st_title="PHP Web Developer 2" class="st_facebook_large" displaytext="facebook"
st_processed="yes"></span></span>
我需要拿 st_url
并且从中删除 php-web-developer-2
所以它只是 http:// localhost:8888 / careers /
。
And I need to take the st_url
and remove the php-web-developer-2
from it so it is just http://localhost:8888/careers/
.
但我不知道该怎么做。 php-web-developer-2
并不总是如此,但它不会有任何 /
。它总是一个 -
分隔的字符串。
But I am not sure how to do that. php-web-developer-2
will not always be that but it won't have any /
in it. It will always be a -
separated string.
任何帮助!! ??
推荐答案
$('span').attr('st_url', function(i, url) {
var str = url.substr(url.lastIndexOf('/') + 1) + '$';
return url.replace( new RegExp(str), '' );
});
DEMO
这篇关于从url中删除最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文