首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

bootstrap collapse

<!doctype html> <html> <head> <meta charset="utf-8"> <title>联想控股</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="css/bootstrap.css" rel="stylesheet" type="text/css"> <script src="http://code.jquery.com/jquery.js"></script> <script src="js/bootstrap.js"></script> </head> <body>

Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
</body> </html>

01

JQuery中bind和unbind函数

测试: 页面代码: <body> <input type="button" name="aaa" value="点击我"> <input type="checkbox" name="checkbox1"> </body> JQuery代码: $().ready(function(){ for (var i = 0; i < 3; i++) { $("input[type='button']").click(function(){ alert("aaaa"); }); } } alert("aaaa")会执行三次,在事件嵌套事件中,不希望看到这样的情况,需要把上层事件禁用,此时可引入bind和unbind函数解决。 引入函数: for (var i = 0; i < 3; i++) { $("input[type='button']").unbind("click"); $("input[type='button']").bind("click", function(){ alert("aaa"); }); } alert("aaa");仅执行一次。 bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数 unbind() 方法移除被选元素的事件处理程序。能够移除所有的或被选的事件处理程序,或者当事件发生时终止指定函数的运行。 event 是事件类型,类型包括:blur、flcus、load、resize、scroll、unload、click、dblclikc、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup和error等,当然也可以是自定义名称。 data 为可选参数,作文event.data属性值传递给事件对象的额外数据对象。 function 是用来绑定的处理函数。 语法: $(selector).bind(event,data,function) // event 和 function 必须指出下面些段代码做说明: 例1:删除p的所有事件 $("p").unbind(); 例2:删除p的click事件 $("p").unbind("click"); 例2:删除p元素click事件后出发的test函数 和 添加p元素click事件后触发的test函数 $("p").unbind("click",test);$("p").bind("click",test); 注意:要定义 .bind() 必须指明什么事件和函数现在来看个简单的demo ,整个div有一个点击收起展开的事件,如果想要点击链接但是不触发div的点击事件,需要在触发链接的时候把div的点击事件禁用,这里我用到链接mouseenter事件是unbind删除div的事件。这里还不算完,这时候只要鼠标进入链接区域,div的点击事件就删除了,我们还需要加入鼠标移出链接区域的时候恢复div点击事件。代码如下: 12345678910$(function(){ var Func = function(){ $(".com2").toggle(200); } $(".test").click(Func) $(".test a").mouseenter(function(){ $(".test").unbind(); //删除.test的所有事件 }); $(".test a").mouseleave(function(){ $(".test").bind("click",Func); //添加click事件 }); });event 是事件类型 … function 是用来绑定的处理函数。 部分内容来自http://www.dearoom.com/blog/详解unbind和bind/http://www.dearoom.com/blog/事件捕获事件冒泡和阻止事件冒泡/

02
领券