function buildTree()
{
//$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
$('.tree li.parent_li > span').on('click', function (e) {
var children = $(this).parent('li.parent_li').find(' > ul > li');
if (children.is(":visible")) {
children.hide('fast');
$(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
} else {
children.show('fast');
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
}
e.stopPropagation();
});
$('.child_li').on('click', function (e) {
$(this).toggle(
function(){
$("input",$(this)).attr("checked",true)
},
function(){
$("input",$(this)).attr("checked",false)
});
});
}
本来是在做一个UL树,parent_li为父节点,child_li为子节点。写点击事件时发现,当子节点点击方法里用toggle时,会先触发父节点的点击事件。其他方法均无影响。不明白原理为何。

jQuery toggle方法的一个奇怪表现。的更多相关文章

  1. jquery toggle()方法 语法

    jquery toggle()方法 语法 作用:toggle() 方法用于绑定两个或多个事件处理器函数,以响应被选元素的轮流的 click 事件.该方法也可用于切换被选元素的 hide() 与 sho ...

  2. jQuery toggle() 方法与实例以及代替方法。

    看<jQeury 权威指南>时看到这个toggle()方法.因为之前在慕课网学习接触过.发现两者讲的有细微的不同 以隐藏/显示目标元素效果为例,慕课网是这样讲解的 $("#cli ...

  3. jquery toggle 方法被废除的替代方法

    今天使用 toggle 方法的时候,该方法一直不能生效. 原来jquery 的引入文件是1.9,该方法在1.8以上已被废除. 那么简单的切换状态,我们可使用if 语句进行代替 如下: 记录一开始设置隐 ...

  4. jquery toggle方法

    $("#myDiv").toggle(function () { alert(1); }, function () { alert(2); }); 某种需求下可以替代click事件 ...

  5. jquery toggle方法使用出错?请看这里-遁地龙卷风

    这个函数在1.9之前和1.9之后的用法大不相同 1 1.9之间,用于点击元素时函数的轮流执行 toggle(function() { alert(1);//1,3,5,7... },function( ...

  6. jQuery中hover方法和toggle方法使用指南

    jQuery提供一些方法(如:toggle)将两种事件效果合并到一起,比如:mouseover.mouseout:keyup.keydown等 1.hover函数 hover(over,out)一个模 ...

  7. jQuery使用toggle()方法进行显示隐藏

    转自:https://www.cnblogs.com/sosoft/p/3460556.html 这是一个示例: 1 <html> 2 <head> 3 <script ...

  8. JQuery 的toggle() 方法如何使用?

    JQuery中的toggle()方法,相当于点一个元素时,重复循环两个函数,而这两个函数可以作为toggle()函数的两个参数传进去,当第一次点击的时候会执行前面的参数,而第二次点击时执行的是后面的参 ...

  9. 使用jQuery的toggle()方法对HTML标签进行显示、隐藏操作

    这是一个示例: <html> <head> <script type="text/javascript" src="https://code ...

随机推荐

  1. 寻找最合适的view

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  2. Hadoop JobHistory

    hadoop jobhistory记录下已运行完的MapReduce作业信息并存放在指定的HDFS目录下,默认情况下是没有启动的,需要配置完后手工启动服务. mapred-site.xml添加如下配置 ...

  3. Party Games

    Party Games You've been invited to a party. The host wants to divide the guests into 2 teams for par ...

  4. 对iframe跨域通信的封装

    github源码:https://github.com/boycy815/topProxy 为了偷懒所以依赖了Kissy:http://docs.kissyui.com/ 用法举例:需求是在http: ...

  5. 【练习】数据文件的更改:改名或改路径 users01.dbf-->users01_bak.dbf

    方法一:1.将数据文件的状态offline SQL> select file_name,tablespace_name from dba_data_files where file_name l ...

  6. centos 7 安装mariadb

    卸载mysql # rpm -qa|grep mysql mysql-community-common-5.6.30-2.el7.x86_64 mysql-community-libs-5.6.30- ...

  7. USACO Section 3.3 游戏 A Game

    OJ:http://www.luogu.org/problem/show?pid=2734 #include<iostream> #include<cstring> using ...

  8. oracle 将查询到的数据插入表

    1. 新增一个表,通过另一个表的结构和数据 create table tab1 as select * from tab2 2. 如果表存在: insert into tab1 select * fr ...

  9. python线程使用场景 多线程下载

    http://blog.xiayf.cn/2015/09/11/parallelism-in-one-line http://python.jobbole.com/84327/ http://www. ...

  10. Magento修改css样式更新之——grunt命令使用

    1.清除pub/static和var中相应文件 2.源头文件重新导入pub/static 3.pub中的less编译 4.字面翻译是跟踪源头文件变化实时编译,但是这里的the source files ...