当前位置:编程学习 > JAVA >>

jQuery事件大全(4)

jQuery事件大全 
 
attribute: 
[html] 
$(" p" ).addclass(css中定义的样式类型)   给某个元素添加样式   
$(" img" ).attr({src:" test.jpg"   alt:" test image" })   给某个元素添加属性/值 参数是map   
$(" img" ).attr(" src"   " test.jpg" )   给某个元素添加属性/值   
$(" img" ).attr(" title"    function() { return this.src })   给某个元素添加属性/值   
$(" 元素名称" ).html()   获得该元素内的内容(元素 文本等)   
$(" 元素名称" ).html(" < b> new stuff< /b> " )   给某元素设置内容   
$(" 元素名称" ).removeattr(" 属性名称" ) 给某元素删除指定的属性以及该属性的值   
$(" 元素名称" ).removeclass(" class" ) 给某元素删除指定的样式   
$(" 元素名称" ).text()   获得该元素的文本   
$(" 元素名称" ).text(value)   设置该元素的文本值为value   
$(" 元素名称" ).toggleclass(class) 当元素存在参数中的样式的时候取消 如果不存在就设置此样式   
$(" input元素名称" ).val()   获取input元素的值   
$(" input元素名称" ).val(value)   设置input元素的值为value   
 
 
manipulation: 
[html] 
$(" 元素名称" ).after(content)   在匹配元素后面添加内容   
$(" 元素名称" ).append(content)   将content作为元素的内容插入到该元素的后面   
$(" 元素名称" ).appendto(content)   在content后接元素   
$(" 元素名称" ).before(content)   与after方法相反   
$(" 元素名称" ).clone(布尔表达式) 当布尔表达式为真时 克隆元素(无参时 当作true处理)   
$(" 元素名称" ).empty() 将该元素的内容设置为空   
$(" 元素名称" ).insertafter(content)   将该元素插入到content之后   
$(" 元素名称" ).insertbefore(content)   将该元素插入到content之前   
$(" 元素" ).prepend(content)   将content作为该元素的一部分 放到该元素的最前面   
$(" 元素" ).prependto(content)   将该元素作为content的一部分 放content的最前面   
$(" 元素" ).remove()   删除所有的指定元素   
$(" 元素" ).remove(" exp" )   删除所有含有exp的元素   
$(" 元素" ).wrap(" html" )   用html来包围该元素   
$(" 元素" ).wrap(element)   用element来包围该元素   
 
 
traversing:  
[html] 
add(expr)   
add(html)   
add(elements)   
children(expr)   
contains(str)   
end()   
filter(expression)   
filter(filter)   
find(expr)   
is(expr)   
next(expr)   
not(el)   
not(expr)   
not(elems)   
parent(expr)   
parents(expr)   
prev(expr)   
siblings(expr)  
 
 
core:  
[html] 
$(html).appendto(" body" ) 相当于在body中写了一段html代码   
$(elems) 获得dom上的某个元素   
$(function(){……..})   执行一个函数   
$(" div >   p" ).css(" border"    " 1px solid gray" )   查找所有div的子节点p 添加样式   
$(" input:radio"    document.forms[0]) 在当前页面的第一个表单中查找所有的单选按钮   
$.extend(prop) prop是一个jquery对象    
举例:    
jquery.extend({   
min: function(a   b) { return a <   b ? a : b   }    
max: function(a   b) { return a >   b ? a : b   }   
})    
jquery( expression   [context] ) ---$( expression   [context])   在默认情况下 $()查询的是当前html文档中的dom元素。  
 
 
each( callback ) 以每一个匹配的元素作为上下文来执行一个函数 
[html]  
举例:1   
$(" span" ).click(function){   
$(" li" ).each(function(){   
$(this).toggleclass(" example" )    
})    
})    
举例:2    
$(" button" ).click(function () {   
$(" div" ).each(function (index   domele) {   
// domele == this   
$(domele).css(" backgroundcolor"    " yellow" )    
if ($(this).is(" #stop" )) {   
$(" span" ).text(" stopped at div index #"   + index)    
return false    
}   
})    
})    
 
 
jquery event:
ready(fn)   $(document).ready()注意在body中没有onload事件 否则该函数不能执行。在每个页面中可以 
有很多个函数被加载执行 按照fn的顺序来执行。 
bind( type   [data]   fn ) 为每一个匹配元素的特定事件(像click)绑定一个或多个事件处理器函数。可能的事件属性有:blur   focus   load   resize   scroll   unload   click   dblclick   mousedown   mouseup   mousemove 
mouseover   mouseout   mouseenter   mouseleave   change   select   submit   keydown   keypress 
keyup   error 
one( type   [data]   fn ) 为每一个匹配元素的特定事件(像click)绑定一个或多个事件处理器函数。在每个对 
象上 这个事件处理函数只会被执行一次。其他规则与bind()函数相同。
[html]  
trigger( type   [data] ) 在每一个匹配的元素上触发某类事件。   
triggerhandler( type   [data] ) 这一特定方法会触发一个元素上特定的事件(指定一个事件类型) 同时取消浏览器对此事件的默认行动   
unbind( [type]   [data] ) 反绑定 从每一个匹配的元素中删除绑定的事件。   
$(" p" ).unbind() 移除所有段落上的所有绑定的事件   
$(" p" ).unbind( " click"   ) 移除所有段落上的click事件   
hover( over   out ) over out都是方法   当鼠标移动到一个匹配的元素上面时 会触发指定的第一个函数。当鼠标移出这个元素时 会触发指定的第二个函数。   
$(" p" ).hover(function(){   
$(this).addclass(" over" )    
}    
function(){   
$(this).addclass(" out" )    
}   
)    
  
toggle( fn   fn ) 如果点击了一个匹配的元素 则触发指定的第一个函数 当再次点击同一元素时 则触发指定的第二个函数。   
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,