怎么使用jquery获得标签的值或元素的内容

在jquery中,你能够获得标签的值或元素的内容从已经选择的标签中。

例如:

1 选择一个标签名为p的标签,并展示其标签的值。

$('p').html();

2 选择一个类名为class1的标签,并展示其值,不管标签名如何。

$('.class1').html();

3 选择一个id为id1的标签,并展示其值,不管标签名如何。

$('#id1').html();

Jquery 实例:

<html>
	<head>
		<title>jquery get tag value</title>
		<script type="text/javascript" src="../jquery-1.11.1.min.js"></script>
	</head>
	<script type="text/javascript">
		$(document).ready(function(){
			var $temp=$('p').html();
			alert($temp);
			var $temp=$(".class1").html();
			alert($temp);
			
			var $temp=$("#id1").html();
		  alert($temp);	
			
			
			});
		
		</script>
	<body>
		<h1>jquery get tag value</h1>
		<p> 
			thisa paragrap1
			</p>
			<div class="class1">
			this is class='class1'
			</div>
			<div id="id1">
			this is id='id1'
			</div>
	</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值