且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JavaScript从重写的URL获取参数

更新时间:2023-11-27 11:26:16

JavaScript不能使用带有查询字符串的重写格式.

The rewritten format, with the query-string, isn't available to your JavaScript.

您必须从location.pathname(在您的示例中为/1/my-event)中获取值,

You'll have to grab the value out of location.pathname (/1/my-event in your example), instead:

var params = window.location.pathname.split('/').slice(1); // ["1", "my-event"]

var id = params[0];
var name = params[1];