.attr("href") with links containing commas
Hay i have a link like this
index.php?sometext=f,fsdsd,rerw,e,wewewe
and when i use .attr("href") on the link, it stops at the fi开发者_运维技巧rst comma, so it only displays
index.php?sometext=f
Any idea how to get ALL the href value
You should replace ,
with %2C
in your links. This is URL encoding.
Commas are among the characters that should be urlencoded when present in a URL, that is, in their case, replaced with %2C
.
$('a').each(function(i, el){
var href = $(this).attr('href');
if (href.split('?').length == 2) {
var dir = href.split('?')[0], query = href.split('?')[1];
$(this).attr('href', dir + '?' + encodeURI(query));
}
});
encodeURI
精彩评论