<script type =”text/javascript” >
$(function() {
$(“p”).text(“这是p标签”);
});
</script>
</head>
<body>
<p></p>
<p></p> <p></p> <p></p> <p></p>
<p></p>
</body>
</html>
在浏览器中运行的效果为:

在dom加载完成后为每一个p元素动态的添加了文本,首先$(“p”)获取p标签的集合,相当于Javascript中的 document.getElementByTagName只是这里得到的是Jquery对象的数组,这样就有了Jquery固有的隐式迭代的功能,后面的text(“这是p标签”)的操作就迭代到了每一个P标签上,我们也可以显示的调用each函数来显示的迭代获得的Jquery对象数组,下面的代码同样可以实现上面的效果:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title></title>
<script src=”../myjs/jquery-1.4.2.js” type=”text/javascript”></script>
<script type =”text/javascript” >
$(function() {
$(“p”).each(function() {
$(this).text(“这是p标签”);
});
});
</script>
</head>
<body>
<p></p>
<p></p> <p></p> <p></p> <p></p>
<p></p>
</body>
</html>










