2013-04-14 129 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