从网址中删除锚点-将字符串添加到网址-并再次在末尾附加锚点 [英] Remove anchor from url - add string to url - and append anchor at the end again

查看:84
本文介绍了从网址中删除锚点-将字符串添加到网址-并再次在末尾附加锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种可转换以下URL的jquery解决方案:

I'm searching for a jquery solution that converts the following URL:

http://www.mysite.com/longpage.html#title3

进入

http://www.mysite.com/longpage.html?var=1#title3

只需添加?var = 1"就没有问题.但是,只有将锚放置在URL的末尾时,锚才会起作用.

Simply adding the "?var=1" is no problem. But the anchor only works when it's placed at the end of the URL.

推荐答案

根据您在问题中所描述的内容,一个简单的替换就可以解决问题:

From what you're describing in your question, a simple replace will do the trick:

"http://www.mysite.com/longpage.html#title3".replace(/(#.+?)$/, '?var=1$1')

这只是普通的JS,因为这就是所有需要的东西.

It's just plain JS because that's all that's needed.

这篇关于从网址中删除锚点-将字符串添加到网址-并再次在末尾附加锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆