本文共 3575 字,大约阅读时间需要 11 分钟。
var img=$("", //新建一个元素 { src:url, //具有html属性 css:{borderWidth:5}, //CSS样式 click:handleClick //事件处理程序 } )
jQuery(function(){ //文档加载时调用 //所有的jQuery代码放这里 })
$("body").length //1 一个文档只有一个body属性 $("body")[0] //等于document.body
例子:
$("button").bind("click",function(){ $("p").slideToggle(); });
替代语法: $(selector).bind({ event:function, event:function, ...})
例子:
$("button").bind({ click:function(){}, mouseover:function(){}, mouseout:function(){} });
$('a').bind('mouseover.myfunction',f) $('a').bind('mouseover.myfunction1.myfunction2',f) //以及分配多个命名空间
$('a').unbind("mouseover.myfunction1") //取消绑定在myfunction1命名空间下的所有事件$('a').unbind('.myfunction1'); //去向绑定在myfunction1于myfunction2下的click事件$('a').unbind('click.myfunction1.myfunction2');
$("img").fadeIn(500).animate({"width","+=100"},{queue:false,duration:1000}) .fadeOut(500);
$("img").stop().animate() $("img").fadeTo(100,0.5).delay(200).slideUp()//快速淡出为半透明,等200ms,然后向上滑动
$.ajax({ url: url, dataType: "script", success: success});