阅读URL参数

如何使用类似于以下的URL读取ID的值?

http://intranet/page.aspx?id=10 

您可以使用JQuery的URL解析器插件 。

 function gup( name ) //stands for get url param { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } var my_param = gup( 'id' ); 

这是jsfiddle ,它使用带有静态url的变量来测试输出。 但是,这是在不使用jQuery的情况下完成的。

http://7php.com/javascript-using-jquery-to-find-url-querystring-or-url-params-a-simple-yet-effective-approach/

这个链接帮我做了同样的事,有jQuery和JavaScript的例子。