2013-04-14 75 views

回答

0

split方法做到这一点:

window.location.href.split('_')[0] 
+0

[0]是什么意思? –

+0

'split()'返回一个数组,'[0]'将指定返回数组的* first *元素;这是在位置被拆分的'_'之前的URL的一部分。 –

+0

非常感谢您亲爱的 –

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