Javascript jQuery 添加 URL 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32317643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery add URL parameter
提问by Legend1989
I have a jquery multiple drag and drop file uploader using dropzone.js.
我有一个使用 dropzone.js 的 jquery 多拖放文件上传器。
I have added the following code to the dropzone code
我已将以下代码添加到 dropzone 代码中
this.on("queuecomplete", function (file) {
alert("&success=yes");
});
So when the queue has completed it sends an alert at the moment however I want to change it so it so that using jquery it adds this as a parameter to the URL.
因此,当队列完成时,它此时会发送警报,但是我想对其进行更改,以便使用 jquery 将其作为参数添加到 URL。
Any ideas how to do this using jquery?
任何想法如何使用 jquery 做到这一点?
回答by Leo Javier
This will do the job...
这将完成工作......
this.on("queuecomplete", function (file) {
var url = document.location.href+"&success=yes";
document.location = url;
});
Option two (in case you already have one parameter)
选项二(如果您已经有一个参数)
this.on("queuecomplete", function (file) {
if(document.location.href.contains('?')) {
var url = document.location.href+"&success=yes";
}else{
var url = document.location.href+"?success=yes";
}
document.location = url;
});