Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
如何使用jQuery更改超链接的href?_Jquery - Fatal编程技术网

如何使用jQuery更改超链接的href?

如何使用jQuery更改超链接的href?,jquery,Jquery,如何使用jQuery更改超链接的href <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("a").each(function(){ var href = $(this).attr('href');

如何使用jQuery更改超链接的href

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

        $("a").each(function(){

         var href = $(this).attr('href');
         alert(href);
         var reg =href+'hiii' ;
          alert(reg);

         $(this).attr("href", reg);
            alert($(this).text())
        });

    });
</script>

<button>Alert the value of each list item</button>
<ul>
<a href="yuyuyuyuyuy"><p>If you click on me, I will disappear.</p></a>
<a href="ioooo"><p>If you click on me, I will disappear.</p></a>
</ul>

$(文档).ready(函数(){
$(“a”)。每个(函数(){
var href=$(this.attr('href');
警报(href);
var reg=href+'hiii';
警报(reg);
$(this.attr(“href”,reg);
警报($(this).text())
});
});
提醒每个列表项的值

这就是为什么你可以在网站上为会员链接编辑来编辑链接,删除jquery alart这是非常基本的谷歌搜索用法

答案是: 1.为该标记设置一个id,如下所示

<a id="my_link"></a>
$("#my_link").attr("href", "your_link")