【问题标题】:Remove part of URL with jQuery [duplicate]使用 jQuery 删除部分 URL [重复]
【发布时间】:2015-05-28 19:03:21
【问题描述】:

如果部分 URL 是可变的,我将如何使用 jQuery 删除部分 URL?

例如如何从我的 URL 中删除它:?modal=name

当 'name' 可能是 name1 name2name3

我想我需要拆分 URL,但是当模式名称可能是任何东西时,我该怎么做呢?

【问题讨论】:

标签: javascript jquery url split


【解决方案1】:
var url = 'http://yourdomain.com/search?modal=name';

alert(url.substring(0, url.indexOf('?')));

Demo

【讨论】:

    【解决方案2】:

    正如您所问的“如何使用 jQuery 删除 URL 的一部分”

    这里有一个基本的解决方法:

    //the URL ( decode it just for GOOD practice)
    var someRandomUrl = decodeURI("http://example.com?modal=name");
    
    //here we do the splitting
    var splittedParts = someRandomUrl.split("?");
    
    // the first part of the array will be URL you will require
    var theURL = splittedParts[0];
    
    // the second part of the array will be the Query String
    var theQuery = splittedParts[1];
    alert(theURL);

    【讨论】:

      猜你喜欢
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2020-12-21
      • 1970-01-01
      相关资源
      最近更新 更多