Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是想知道是否有可能从 js 调用中检索参数,使用这样的传递值
myfile.js?my_parm=brol
我的目标是my_param从我的“myfile.js”中检索值
my_param
提前致谢
请参阅在 .js 文件中调用 URL 参数
不,不是从 JavaScript 中访问,在 JavaScript 中访问查询字符串参数的唯一方法是通过文档或位置对象。这些仅在脚本在浏览器中执行时可用。
如果您尝试使用模板语言(如 php 或 python)访问它,您当然可以捕获查询字符串参数并将信息注入到 JavaScript 代码中。