Javascript 替换href属性中文本的值
我试图在DOM就绪时将expand的值更改为0 我试过不同的方法Javascript 替换href属性中文本的值,javascript,jquery,Javascript,Jquery,我试图在DOM就绪时将expand的值更改为0 我试过不同的方法 $('.link-comment').attr('href').find("expand=1").replaceWith('expand=0'); 但它不起作用。因此,我可以将expand的值更改为0 <a class="link-comment" href="/eventcomments/create-like/227?expand=1"> 试着这样做: $(function(){ $('.link-c
$('.link-comment').attr('href').find("expand=1").replaceWith('expand=0');
但它不起作用。因此,我可以将expand的值更改为0
<a class="link-comment" href="/eventcomments/create-like/227?expand=1">
试着这样做:
$(function(){
$('.link-comment').attr('href', function (_, cur) {
return cur.replace(/expand=1/, "expand=0");
});
});
试试看
$('.link-comment').filter('[href*="expand=1]"').attr('href', function(idx, href){
return href.replace('expand=1', 'expand=0')
})
试试这个:
$('.link-comment').attr('href',$('.link-comment').attr('href').replace("expand=1", "expand=0"));