当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery中each方法教程示例和常用选择器

jquery中each方法教程示例和常用选择器

2019年03月25日  | 移动技术网IT编程  | 我要评论
<head> <title></title> <script src="jquery-1.4.2.js&quo
 <head> 
<title></title> 

<script src="jquery-1.4.2.js" type="text/javascript"></script> 
<script type="text/javascript"> 

$(function() { 
//alert($("p").text()); 
//对数组元素使用匿名函数进行逐个处理。 
$("p").each(function(key, value) { 
//alert(key+value); 
// alert($(value).text()); 
alert(this.innerhtml); 
}); 
//this表示当前遍历的dom元素 
$("p").each(function() { 
alert($(this).text()); 
}); 
}); 
</script> 
</head> 
<body> 
<p id="testdom">11111</p> 
<p>2222</p> 
<p>33333</p> 
</body>

常用选择器:

1.类:$(".error").
2.id:$("#dalong").
3.标签:$("p").
4.属性:$("p[name=apple]").
5.表单:$("input:checked").

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网