JavaScript字符串替换URL参数
我目前正在尝试更改帮助链接。 帮助手册的URL有一个pageid。当您浏览我们的应用程序时,链接和页面ID会发生变化 url的一个示例是: 目前我正在使用JavaScript字符串替换URL参数,javascript,jquery,Javascript,Jquery,我目前正在尝试更改帮助链接。 帮助手册的URL有一个pageid。当您浏览我们的应用程序时,链接和页面ID会发生变化 url的一个示例是: 目前我正在使用 function ReplaceHelpLink(pageId) { $(".helpLinkReplace", document).each(function (index, helpLink) { helpLink.href = helpLink.href.replace("#pageid", pageId);
function ReplaceHelpLink(pageId) {
$(".helpLinkReplace", document).each(function (index, helpLink) {
helpLink.href = helpLink.href.replace("#pageid", pageId);
});
}
但这无法处理这种情况,例如,当url发生更改时
你会怎么处理?感谢您的帮助和时间。您需要更换更像这样的东西:
function ReplaceHelpLink(pageId) {
$(".helpLinkReplace", document).each(function (index, helpLink) {
var link = $(this).attr("href").replace("#pageid", pageId);
$(this).attr("href",link);
});
}
....replace(/#pageid|\d+/,pageId);
这将同时处理第一次替换和后续替换的情况。您何时调用此函数?在应用程序中的页面之间移动请在调用时发布代码。ink.Attributes[“OnClick”]=“ReplaceHelpLink”(+Convert.ToInt32(siteMapNode[“pageId”])+”;我认为按您现在的方式设置onclick事件不是正确的方法。您必须执行ink.onclick=ReplaceHelpLink(Convert.ToInt32(siteMapNode.pageId));