jQuery / Javascript替换< space>与%20的锚链接 [英] jQuery / Javascript replace <space> in anchor link with %20
本文介绍了jQuery / Javascript替换< space>与%20的锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jQuery的新手,我正在尝试编写一些代码来浏览页面并重写锚链接href属性,以便空格被删除并替换为%20。
I'm new to jQuery and i'm trying to write some code to go through the page and rewrite anchor links href attribute so that spaces are removed and replaced with %20.
到目前为止我有:
so far i have:
$(".row a").each(function(){
$(this).attr("href").replace(/\s/g,"%20");
});
我试过几次这样的变化,没有运气。
I've tried a few variations of this with no luck.
推荐答案
您的方法是正确的,但您在替换它时忘记设置新值。试试这个:
Your approach is correct, but you're forgetting to set the new value once you replace it. Try this:
$(".row a").each( function() {
this.href = this.href.replace(/\s/g,"%20");
});
这篇关于jQuery / Javascript替换< space>与%20的锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文