admin 管理员组

文章数量: 1086019

i need to remove the first "/" in my url. As you can see my first value is correct, now i need to do the same to the second url. How can i delete the first "/"

option=_content&view=article&id=2&Itemid=2     <    CORRECT
/option=_content&view=article&id=2&Itemid=2     <   NOT GOOD FOR ME

i need to remove the first "/" in my url. As you can see my first value is correct, now i need to do the same to the second url. How can i delete the first "/"

option=_content&view=article&id=2&Itemid=2     <    CORRECT
/option=_content&view=article&id=2&Itemid=2     <   NOT GOOD FOR ME
Share Improve this question edited Jan 24, 2011 at 19:23 Zack The Human 8,4918 gold badges42 silver badges61 bronze badges asked Jan 24, 2011 at 17:08 DeeDee 3,25510 gold badges38 silver badges40 bronze badges 6
  • Where is the URL ing from? In what context is this? – Pekka Commented Jan 24, 2011 at 17:10
  • What is the context? Where is the URL? In a variable? Link? – Felix Kling Commented Jan 24, 2011 at 17:10
  • 5 14 of your questions are eligible for one of the answers to be accepted. You have currently accepted 0 answers. Please see stackoverflow./faq#howtoask for more information. – Andy E Commented Jan 24, 2011 at 17:17
  • Is that really the correct url since it seems to be a / in a path and a querystring. Its possible that there is no query part and that what looks like that is actual the resource being pointed at but this seems unlikely... – Chris Commented Jan 24, 2011 at 17:19
  • 1 I'm not sure if this question really has anything to do with jQuery -- is there a reason why it's called out in the title/tags? – Zack The Human Commented Jan 24, 2011 at 17:24
 |  Show 1 more ment

2 Answers 2

Reset to default 5

Different way

var rawurl = "/option=_content&view=article&id=2&Itemid=2";

rawurl = rawurl.substr(rawurl.indexOf('/') + 1);

Try this -

var str = "/option=_content&view=article&id=2&Itemid=2";

str.replace(/\//, "");

Note: In this answer i have assumed you to save this part of url in variable str first.

本文标签: How to remove the first slash in my URL with JavaScriptStack Overflow