网络编程
位置:首页>> 网络编程>> JavaScript>> jQuery使用手册--核心篇(Core)(4)

jQuery使用手册--核心篇(Core)(4)

作者:Young.J 来源:jquery.org.cn 发布时间:2007-11-22 22:05:00 

标签:jQuery,手册

each(fn)

说明:将函数作用于所有匹配的对象上

参数:fn (Function): 需要执行的函数

例子:未执行jQuery前:


<img src="1.jpg"/>
<img src="1.jpg"/>
<a href="#" id="test" onClick="jq()">jQuery</a>   jQuery代码及功能: 
function jq(){
   $("img").each(function(){ 
        this.src = "2.jpg"; });


运行:当点击id为test的元素时,img标签的src都变成了2.jpg。

eq(pos)

说明:减少匹配对象到一个单独得dom元素

参数:pos (Number): 期望限制的索引,从0 开始

例子:未执行jQuery前:


<p>This is just a test.</p>
<p>So is this</p>
<a href="#" id="test" onClick="jq()">jQuery</a> 

jQuery代码及功能:



function jq(){
    alert($("p").eq(1).html())


运行:当点击id为test的元素时,alert对话框显示:So is this,即第二个<p>标签的内容

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com