我想,直到一个特殊字符匹配的网址“_”(如果存在)之前jQuery的匹配URL特殊字符
var url = window.location;
VAR URL应该得到URL的一部分“_” http://www.example.com/index.php?route=product/category&path=25_10
之前即 http://www.example.com/index.php?route=product/category&path=25
我想,直到一个特殊字符匹配的网址“_”(如果存在)之前jQuery的匹配URL特殊字符
var url = window.location;
VAR URL应该得到URL的一部分“_” http://www.example.com/index.php?route=product/category&path=25_10
之前即 http://www.example.com/index.php?route=product/category&path=25
split方法做到这一点:
window.location.href.split('_')[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
[0]是什么意思? –
'split()'返回一个数组,'[0]'将指定返回数组的* first *元素;这是在位置被拆分的'_'之前的URL的一部分。 –
非常感谢您亲爱的 –