javascript - 如何从由斜杠分隔的 url 中获取 url 参数,例如 http://myweb.com/example/12345/222/4444 我想从上面的 url 中获取 12345、222、4444
问题描述
试图获取最后一个参数以进行进一步处理,但无法将它们分开。
解决方案
您可以在获取urlsplit
后使用 JS 的功能来做到这一点。pathname
const url = 'http://myweb.com/12345/222/4444';
const a = document.createElement('a');
a.href = url;
const pathname = a.pathname.substring(1);
console.log(pathname.split('/'));
推荐阅读
- mono - Mono 返回 ConsoleApp: EPIC FAIL
- riscv - RISC-V I-Type 的直接字段中的地址可以是负数吗?
- android - Android Retrofit:发布和调试版本中的响应 200 但发布版本返回空值
- php - 在 WordPress 中使用大写字母和数字生成随机字符串
- java - 如何获取 TreeTableView 的行数?
- django - 如何使用 Django ORM 跳过带有条件的列检查
- javascript - 在 React 中不使用条件渲染时无法读取属性“地图”
- python - 在 Spark 上运行依赖于 Numpy 的 python 代码时出现问题
- javascript - 屏幕关闭时在手机上播放视频
- flutter - 应用程序在不同设备上弄乱了小部件