jQuery:将字符串添加到 URL
我正在使用这段代码从单击的链接中获取 url:
var url = $(this).find('a').attr('href');
我想向该 url 添加一个字符串。
例如,我当前的网址是:
我想将其设置为:
http://mydomain.com/myarticle-chinese
我应该在我的第一行代码中添加什么来实现这一点?
我将不胜感激您的建议!
附录:非常感谢!四个人几乎同时回答,四个人都给了我有用的答案。我希望我能接受全部四个!
I'm using this snippet of code to grab a url from a clicked link:
var url = $(this).find('a').attr('href');
I want to add a string to that url.
For example, my current url is:
I want to make it:
http://mydomain.com/myarticle-chinese
What should I add to my initial line of code to make that happen?
I'd be grateful for your advice!
ADDENDUM: THANK YOU VERY MUCH! FOUR PEOPLE ANSWERED ALMOST SIMULTANEOUSLY AND ALL FOUR GAVE ME A HELPFUL ANSWER. I WISH I COULD ACCEPT ALL FOUR!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这会将新值存储在
url
: 中,并且这将重定向用户的浏览器:
This will store the new value in
url
:and this will redirect the user's browser:
您想将字符串“-chinese”附加到检索到的 URL 中吗?试试这个:
You want to append the string "-chinese" to the retrieved URL? Try this: