jQuery基础事件-绑定事件

来源:互联网 发布:阿里云免费半年邀请码 编辑:程序博客网 时间:2024/05/18 03:45
js中的事件
 click,dblclick,mousedown,mouseup,mousemove,mouseout,change,
 select,submit,keydown,keypress,keyup,blur,focus,load,resize,scroll,
 error


 1.绑定事件
 2.简写事件
 3.复合事件
//绑定事件
/**
$(function(){
$('input').bind('click',function(){
alert('click事件');
});//利用bind方法绑定,两个参数,第一个为事件类型,第二个是事件
})
*/
//事件方法和绑定分离,方法在自己定义
/**
$(function(){
function fun(){//自己定义的函数
alert('点击绑定的事件');
}


$('input').bind('click',fun);//绑定到事件上
})
*/


//绑定多个事件
/**
$(function(){
$('input').bind('mouseover mouseout',function(){
alert('move');
});
})
*/
//分开绑定事件
/**
$(function(){
$('input').bind({
mouseover:function(){
alert('mouseover');
},
mouseout:function(){
alert('mouseout');
}
});
})
*/


//解绑
/**
$(function(){
$('input').bind({
mouseover:function(){
alert('mouseover');
},
mouseout:function(){
alert('mouseout');
}
});
//$('input').unbind();//解绑所有绑定的事件
//$('input').unbind('mouseover mouseout');//传递一个要解绑的事件类型,也可以传递多个
})
*/
/**
$(function(){
function fun1(){
alert('fun1');
}
function fun2(){
alert('fun2');
}


$('input').bind('click',fun1);//绑定事件fun1
$('input').bind('click',fun2);//绑定事件fun2


$('input').unbind('click',fun1);//解绑指定的事件


})
*/


//事件绑定简写
/**
$(function(){
/**$('input').click(function (argument) {
alert('click');
});
*/


/**
$('input').mousedown(function (argument) {
alert('mousedown');
})
*/


/**
$('input').mouseleave(function (argument) {
// body...
alert('mouseleave');
})
*/


/**
$(window).resize(function (argument) {
// body...
alert('size change');
})
*/




/**
$(window).scroll(function (argument) {
// body...
alert('scroll');
})
*/
/**
$('input').select(function (argument) {//select是当选中文本内时触发事件
// body...
alert('select');
})
*/


/**
$('input').change(function (argument) {//当文本中的内容被改变时触发事件
// body...
alert('change');
})
*/


/**
$('form').submit(function (argument) {//submit事件绑定在form上,而不是input上
// body...
alert('submit');
})
*/
//})
原创粉丝点击