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

时间:2015-03-27    点击:71   

本文实例讲述了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>

希望本文所述对大家的jQuery程序设计有所帮助。

javascript包装对象实例分析
javascript操作select元素实例分析
jquery使用slideDown实现模块缓慢拉出效果的方法
jQuery使用slideUp方法实现控制元素缓慢收起
jquery使用animate方法实现控制元素移动
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved