Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换href属性中文本的值_Javascript_Jquery - Fatal编程技术网

Javascript 替换href属性中文本的值

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

我试图在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-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"));