为什么不能使用以下jQuery代码?为什么这个jQuery代码不起作用?
$(function() {
var regex = /\?fb=[0-9]+/g;
var input = window.location.href;
var scrape = input.match(regex); // returns ?fb=4
var numeral = /\?fb=/g;
scrape.replace(numeral,'');
alert(scrape); // Should alert the number?
});
基本上我有一个像这样的链接:
http://foo.com/?fb=4
如何首先找到?fb=4
,然后才捡回多少?
谢谢,小心解释这是如何工作的?比赛中的阵列是什么? – daryl 2011-06-02 17:43:02
更好的方法是在'window.location.search'上搜索,以免偶尔在路径或哈希中匹配子字符串。 – digitalbath 2011-06-02 17:44:07
'match'返回匹配数组。 – circusbred 2011-06-02 17:47:03