// 向被选定的元素添加一个或者多个事件处理数据,以及当事件发生时运行的函数
$(this).bind("click",function(){
})
$(this).bind("mouseover mouseout",function(){\
})
// event必填,多个事件用空格分开(必须是有效事件)
// data 可选,规定传输函数额外的数据
// function 必填,规定当事件发生时,运行的函数
// map 规定事件映射
$(this).bind(event,data,function,map)
// 映射事例
$("p").bind({
click:function(){$(this).css("color","red")},
mouseover:function(){$(this).next().css("color","red")
}
})
// data传数据事例
function sl(e){
alert(e.data.mg)
}
$("p").bind("click",{mg:"点击了我一下"},sl)
// 元素发生改变而产生的事件 (适用于表单元素)
$(this).change()
// 元素触发时发生的函数
$(this).click()
// 双击触发dblclick事件(不能与click事件同时用在同一个元素上)
$(this).dblclick()
// 阻止事件冒泡
function stopBubble(e){
if(e && e.stopPropagation){
e.stopPropagation()
}else{
window.event.cancelBubble = true
}
}
// 阻止浏览器默认事件
function stopDefault(e){
if(e && e.preventDefault){
e.preventDefault()
}else{
window.event.returnValue = false
}
}
// 返回X值及Y值
$(this).pageX
$(document).mousemove(function(event){
console.log("X",event.pageX,"Y",event.pageY,)
})
// 可同时插入两个或多个事件 (as是类名)
$("p").on("mouseover mouseout",function(){
$(this).toggleClass("as")
})
// 使用map参数添加多个事件处理程序
$("p").on({
mouseover:function(){$("body").css("background","#000000")},
mouseout:function(){$("body").css("background","#101010")},
click:function(){$("body").css("background","red")}
})