-1
當我說的部分是可以改變的時候,如何用jQuery去掉部分URL?用jQuery去掉URL的一部分
E.g.我怎樣才能從我的網址刪除此:模式=命名
在「名稱」可能是名1名2或NAME3
我想我需要拆分URL,但怎麼辦當模態名稱可能是什麼時,我會這樣做?
當我說的部分是可以改變的時候,如何用jQuery去掉部分URL?用jQuery去掉URL的一部分
E.g.我怎樣才能從我的網址刪除此:模式=命名
在「名稱」可能是名1名2或NAME3
我想我需要拆分URL,但怎麼辦當模態名稱可能是什麼時,我會這樣做?
var url = 'http://yourdomain.com/search?modal=name';
alert(url.substring(0, url.indexOf('?')));
正如你問使用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);
難道你不只是用n代替模態名稱值ame1,name2,...? – Peter 2015-03-25 07:56:43
以防萬一你只想刪除'modal'參數:http://stackoverflow.com/questions/1634748/how-can-i-delete-a-query-string-parameter-in-javascript – 2015-03-25 08:16:02