当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery获取标签文本内容和html内容的方法教程

jQuery获取标签文本内容和html内容的方法教程

2019年05月17日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery获取标签文本内容和html内容的方法。分享给大家供大家参考。具体分析如下:

jquery可以通过text和html方法获取指定标签的文本内容或者html内容

<!doctype html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("#btn1").click(function(){
  alert("text: " + $("#test").text());
 });
 $("#btn2").click(function(){
  alert("html: " + $("#test").html());
 });
});
</script>
</head>
<body>
<p id="test">this is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">show text</button>
<button id="btn2">show html</button>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网