2013-08-05 2 views
0

현재 변경중인 도움말 링크를 만들려고합니다. 도움말 설명서의 URL에 pageid가 있습니다. 애플리케이션을 탐색 할 때 링크 및 페이지 ID가 변경됩니다.JavaScript 문자열 URL 매개 변수 대체

URL의 예는 다음과 같습니다 http://www.google.com/custom?pageid=#pageid

현재

내가

function ReplaceHelpLink(pageId) { 
    $(".helpLinkReplace", document).each(function (index, helpLink) { 
     helpLink.href = helpLink.href.replace("#pageid", pageId); 
    }); 
} 

을 사용하고 있습니다 그러나 이것은 URL이 예를 들어, 변경된 상황을 처리하지 않습니다 http://www.google.com/custom?pageid=1

어떻게 처리할까요? 도와 주셔서 감사합니다.

+0

언제이 기능을 호출합니까? –

+0

신청서에있는 페이지 사이를 이동하면 –

+0

코드를 게시하시기 바랍니다. –

답변

0

당신은 더 이런 일을 대체해야합니다

....replace(/#pageid|\d+/,pageId); 

이 너무 첫번째 교체의 경우, 및 susequent 교체를 모두 처리합니다.

0
function ReplaceHelpLink(pageId) { 
    $(".helpLinkReplace", document).each(function (index, helpLink) { 
     var link = $(this).attr("href").replace("#pageid", pageId); 
     $(this).attr("href",link); 
    }); 
}