jquery插件中的事件 使用方式:
1、通常都是$("...").uploadify({
onStart:function () {...},
...
});
2、jquery的:bind和trigger 使用;
1.trigger(type,[data]) 触发事件,这个方法是jQuery 1.3中新增的一个引起触发事件的函数。
2.为什么要用 trigger() ?比如前台页面里有:<p id="p1">请点击这里!</p>
1)你希望加载页面时就执行这个事件给这个这p绑定了click事件(将下面的代码写在$(function(){});里面):
$("#p1").click(function(){
alert("hello!");
}).trigger(click);//这样,不需要手工去点击,trigger完成了了点击;
2)可以这么说,但是用trigger()最大的好处就是它是可以传递参数进去的。例如:
//myEvent为自定义事件名
$("#p1").bind("myEvent",function(event,str1,str2) {
alert(str1 + ' ' + str2);
});
$("#p1").trigger("myEvent",["Hello","World"]); //Hello为str1、World为str2
也可以这样写:
$("#p1").bind("myEvent",function(event,str1,str2) {
alert(str1 + ' ' + str2);
}).trigger("myEvent",["Hello","World"]);