jquery bind用法
2017-02-13 13:36
309 查看
bind介绍
bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数。
语法
event 必须。添加到元素的一个或多个事件如:click,mouseover,mouseup,change,select
data 可不填。传递到函数的额外数据,如:$(selector).bind(“click”,”input”,function(){});
function(){} 必填。绑定事件触发的函数
bind绑定多个函数
4.bind绑定数据
5.unbind bind事件移除
bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数。
语法
`$(selector).bind(event,data,function)
event 必须。添加到元素的一个或多个事件如:click,mouseover,mouseup,change,select
data 可不填。传递到函数的额外数据,如:$(selector).bind(“click”,”input”,function(){});
function(){} 必填。绑定事件触发的函数
bind绑定多个函数
$("button").bind({ // 注意它的格式是 json click:function(){$("div").css("border","5px solid orange");}, mouseover:function(){$("div").css("background-color","red");}, mouseout:function(){$("div").css("background-color","#FFFFFF");} });
4.bind绑定数据
// bind() 绑定 click 事件传 参数2 并且打印出 参数2 $('button').bind('click',['路飞','索隆','乌索普'],function(event){ alert(event.data[0]); // 路飞 });
5.unbind bind事件移除
html 代码 <button>unbind()</button> <p>点我删除上边按钮的事件</p> js 代码 // bind() 绑定多个点击事件 $('button').click(function(){ alert('我是第一个点击事件'); }); $('button').click(function(){ alert('我是第二个点击事件'); }); $('button').bind('click',function(){ alert('我是第三个点击事件'); }); // un 4000 bind() 删除点击事件 $('p').bind('click',function(){ $('button').unbind('click'); alert('button 的点击事件被删除'); });
相关文章推荐
- JQuery环境搭建
- HTML5 自定义属性 data-* 和 jQuery.data 详解
- jquery实现轮播图效果
- jQuery中常用的元素查找方法总结
- jQuery中常用的元素查找方法总结
- jQuery的选择器
- 处理表格数据时,去除表头两种写法,jquery 删除表头之外的数据
- Jquery,JavaScript性能优化
- jq 查找控件
- jQuery Validate + Ckeditor 验证 textarea (request) 解决方式
- jQuery事件之鼠标事件
- Jquery中关于height,innerheight,outer height的知识小计
- 基于jQuery代码实现圆形菜单展开收缩效果
- jQuery学习 四 jQuery jQuery 遍历
- jQuery源码分析之sizzle选择器详解
- jQuery - AJAX load() 方法
- jquery学习1
- jQuery源码分析之init的详细介绍
- jQuery圆形菜单展开收缩特效
- jquery validate 简单用例