0

我想匹配 url 直到一个特殊字符 '_' 如果它存在

var url = window.location; var url 应该在 '_' http://www.example.com/index.php?route=product/category&path=25_10 之前获取部分 url

http://www.example.com/index.php?route=product/category&path=25

4

2 回答 2

0

split方法会做到这一点:

window.location.href.split('_')[0]
于 2013-04-14T18:18:12.690 回答
0
var href = window.location.href;
// http://www.example.com/index.php?route=product/category&path=25_10

var new_url = href.slice(0, href.indexOf('_'));
// http://www.example.com/index.php?route=product/category&path=25
于 2013-04-14T18:23:46.877 回答