使用JQuery在Window.Location.Href中删除/添加Querystring

时间:2011-04-05 05:02:56

标签: jquery

我正在使用JQuery并遇到一个问题,需要您的帮助和指导。

我想在当前的window.location.href中以下三点进行:

  1. 如果我的?mode=ssl

  2. 中没有任何查询字符串,我想添加window.location.href
  3. 如果&mode=ssl

  4. 中有任何查询字符串,我想附加window.location.href
  5. 我想从logout删除window.location.href个查询字符串,如果存在, 然后将mode=ssl添加到window.location

2 个答案:

答案 0 :(得分:0)

尝试使用Query String Object插件。

答案 1 :(得分:0)

您希望为jQuery使用query插件的内容。使得操作和检索url查询值变得简单易行。因此,使用查询来满足您的要求:

// no need to check for a query string and use `?` or `&`, query does that for us
$.query.set("mode", "ssl");
if ($.query.get("logout")) {
  $.query.set("logout", false);
}