admin管理员组文章数量:1324904
I don't know what I am doing wrong with changing href attribute in link from ?page to &page. It stays on ?page. Thank you for any advice.
Jquery:
var article_pagination_change = function(){
$('pagination a').each(function(){
$(this).href.replace('?page','&page');
});
}
article_pagination_change();
HTML:
<div id="pagination80" class="pagination" style="">
<a class="first" data-action="first" href="?page=1"><<</a>
<a class="previous" data-action="previous" href="?page=1"><</a>
<input class="pag_input_80" type="text" value="1 of 12" data-max-page="12" readonly="readonly">
<a class="next" data-action="next" href="?page=2">></a>
<a class="last" data-action="last" href="?page=12">>></a>
</div>
I don't know what I am doing wrong with changing href attribute in link from ?page to &page. It stays on ?page. Thank you for any advice.
Jquery:
var article_pagination_change = function(){
$('pagination a').each(function(){
$(this).href.replace('?page','&page');
});
}
article_pagination_change();
HTML:
<div id="pagination80" class="pagination" style="">
<a class="first" data-action="first" href="?page=1"><<</a>
<a class="previous" data-action="previous" href="?page=1"><</a>
<input class="pag_input_80" type="text" value="1 of 12" data-max-page="12" readonly="readonly">
<a class="next" data-action="next" href="?page=2">></a>
<a class="last" data-action="last" href="?page=12">>></a>
</div>
Share
Improve this question
asked Mar 28, 2014 at 22:57
user3342042user3342042
2411 gold badge7 silver badges20 bronze badges
1
- that dot is very small I can't see it :) thank you – user3342042 Commented Mar 28, 2014 at 23:01
2 Answers
Reset to default 5You need to actually set the attribute:
var article_pagination_change = function(){
$('.pagination a').each(function(){
var newurl = $(this).attr('href').replace('?page','&page');
$(this).attr('href', newurl);
});
}
article_pagination_change();
Note that I added the .
before pagination
and am using attr('href')
instead of just href
.
Here's a working jsFiddle.
If you don't mind changing your code a bit more, you can try this simpler approach:
var article_pagination_change = function(){
$('.pagination a').attr('href',function(index,attr){
return attr.replace('?','&');
});
}
article_pagination_change();
You don't really need the .each()
nor replacing ?page
with &page
unless you had extra ?
s on your href
s...
Sample JSFiddle
本文标签: javascriptJqueryHow to change part of attribute href in linkStack Overflow
版权声明:本文标题:javascript - Jquery - How to change part of attribute href in link? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742127570a2422011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论