【www.gdgbn.com--jquery】

jquery ready() bind() toggle() addclass()事件处理
jquery中提供的比较常用的几个动态效果的函数。还可以添加参数:show(speed,[callback])以优雅的动画显示所有匹配的元素,并在显示完成后可选地触发一个回调函数。

ready(fn)

代码:

js代码
$(document).ready(function(){  
  // your code here...  
}); 

$(document).ready(function(){
  // your code here...
}); 

作用:它可以极大地提高web应用程序的响应速度。通过使用这个方法,可以在dom载入就绪能够读取并操纵时立即调用你所绑定的函数,而99.99%的网页特效函数都需要在那一刻执行。 

bind(type,[data],fn)

代码:

js代码
$("p").bind("click", function(){  
  alert( $(this).text() );  
});  

$("p").bind("click", function(){
  alert( $(this).text() );
});  

作用:为每一个匹配元素的特定事件(像click)绑定一个事件处理器函数。起到事件监听的作用。

   

toggle(fn,fn)

代码:

js代码
$("td").toggle(  
  function () {  
    $(this).addclass("selected");  
  },  
  function () {  
    $(this).removeclass("selected");  
  }  
); 

$("td").toggle(
  function () {
    $(this).addclass("selected");
  },
  function () {
    $(this).removeclass("selected");
  }
); 

作用:每次点击时切换要调用的函数。如果点击了一个匹配的元素,则触发指定的第一个函数,当再次点击同一元素时,则触发指定的第二个函数。挺有趣的一个函数,在动态实现某些功能的时候可能会用到。(像click(),focus(),keydown()这样的事件这里就不提了,那些都是开发中比较常用到的。)

 jquery外观效果

 

addclass(class)和removeclass(class)

代码:

js代码
$(".stripe tr").mouseo教程ver(function(){    
               $(this).addclass("over");}).mouseout(function(){   
               $(this).removeclass("over");})  
}); 

$(".stripe tr").mouseover(function(){ 
               $(this).addclass("over");}).mouseout(function(){
               $(this).removeclass("over");})
}); 也可以写成:

js代码
$(".stripe tr").mouseover(function() { $(this).addclass("over") });  
$(".stripe tr").mouseout(function() { $(this).removeclass("over") }); 

$(".stripe tr").mouseover(function() { $(this).addclass("over") });
$(".stripe tr").mouseout(function() { $(this).removeclass("over") });

作用:为指定的元素添加或移除样式,从而实现动态的样式效果,上面的实例中实现鼠标移动双色表格的代码

 css教程(name,value)

代码:

$("p").css("color","red");作用:很简单,就是在匹配的元素中,设置一个样式属性的值。这个个人感觉和上面的addclass(class)有点类似。 

slide(),hide(),fadein(), fadeout(), slideup() ,slidedown()

代码:

$("#btnshow").bind("click",function(event){ $("#divmsg").show() });
$("#btnhide").bind("click",function(evnet){ $("#divmsg").hide() });

本文来源:http://www.gdgbn.com/wangyezhizuo/28888/