javascript - 将当前 URL 参数附加到锚链接上
问题描述
在像这样的页面
https://www.example.com/?firstname=Steven&lastname=Smith&email=steve%40gmail.com&phone=0404555555
我有一个#ptsBlock_553944 .ptsCell:nth-of-type(1) .ptsEditArea.ptsInputShell
链接到的按钮(锚链接)https://www.example.com/form
我想将当前 URL 中的 URL 参数附加到按钮的 URL,以便按钮的 href 现在是https://www.example.com/form/?firstname=Steven&lastname=Doig&email=steve%40gmail.com&phone=0404555555
请问如何用 JavaScript 做到这一点?
解决方案
使用window.location.search
:
var url = "https://exmaple.com";
var newurl = url + window.location.search;
newurl
将包含所有get
(例如?something=something&something2=something5
)数据。
要更改href
:a
var button = document.getElementById('#ptsBlock_553944');
button.href = button.href + window.location.search;
推荐阅读
- git - 如何在不丢失更改的情况下重置分支的所有提交?
- flutter - 如何调用 LogicalKeyboardKey.cut/copy/paste
- shopify - 在哪里存储公共 Shopify 应用程序的设置
- python - Discord.py(机器人两次发送响应/两次运行命令)
- python - 为什么此代码会生成类型注释警告?
- javascript - 如何使用 Google Analytics 跟踪 URL 查询参数
- javascript - Mongoose Populate 返回空数组 - 范围问题
- laravel - 如何覆盖 Laravel 的 CKFinder 默认上传功能
- java - 如何使用 Java 流合并和置换数组?
- python-3.x - 允许用户下载文件然后重定向到其他页面