jquery如何替换a标签中间的内容

这篇文章主要介绍jquery如何替换a标签中间的内容,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

jquery替换a标签中间内容的方法:1、利用“$(a标签元素)”语句获取指定的a标签元素对象;2、利用html()方法来替换a标签中间的内容,语法为“a标签元素对象.html(要替换的内容);”。

本教程操作环境:windows7系统、jquery3.2.1版本、Dell G3电脑。

我们可以通过html()方法来替换a标签中间的内容。当使用该方法设置一个值时,它会覆盖所有匹配元素的内容。

语法如下:

$(selector).html(content)

示例如下:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#jquery").html("123");
  });
});
</script>
</head>
<body>
<a href="course/list/19.html" target="_blank" id="jquery">jQuery视频教程</a>
<button id="btn1">替换a标签中间的内容</button>
</body>
</html>

输出结果:

jquery如何替换a标签中间的内容

以上是“jquery如何替换a标签中间的内容”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!