我想,直到一個特殊字符匹配的網址「_」(如果存在)之前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的一部分。 –
非常感謝您親愛的 –