为什么jQuery在鼠标移动/悬停时切换不断变化(Why is jQuery toggle continually changing on mouse movement/hover)
通过这里的答案,我刚刚得到了jQuery中的这些代码 -
$('.folder-items a').hover(function(){ $(this).siblings('.file-hover').toggle(); });
.folder-items
a.folder-items
在里面。 我希望能够悬停整个'li'而不仅仅是在实际的<a>
上显示.file-hover
div。我已经在jsfiddle中创建了它 - http://jsfiddle.net/8Sefc/8/ - 但是当我的鼠标移动到li时,它显示/隐藏像疯了一样...
我认为这是我的CSS和显示:块; 宽度:100%; 李和李一个,但不能找出另一种方式来做到这一点...
想法?
I've just got this bit of code working in jQuery via an answer on here -
$('.folder-items a').hover(function(){ $(this).siblings('.file-hover').toggle(); });
the
.folder-items
a is within a li. I want to be able to hover the whole 'li' and not just on the actual<a>
to show the.file-hover
div.I've created this in jsfiddle - http://jsfiddle.net/8Sefc/8/ - but when moving my mouse around the li it's showing/hiding like crazy...
I think it's something up with my CSS and display: block; width: 100%; of the li and li a but can't work out another way to do this...
Ideas?
原文:https://stackoverflow.com/questions/9344834
最满意答案
strcpy(t->buffer, file_name);
正在写一个未初始化的指针。 您需要为
buffer
分配内存。 如果您使用的是Posix兼容系统,最简单的方法是使用strdup
t->buffer = strdup(file_name);
否则,您需要分配内存然后单独复制
t->buffer = malloc(strlen(file_name)+1); strcpy(t->buffer, file_name);
在任何一种情况下,当你为每个
node
释放内存时,你需要free(t->buffer)
strcpy(t->buffer, file_name);
is writing to an uninitialised pointer. You need to allocate memory for
buffer
. If you're on a Posix-compatible system, the easiest way to do this is by usingstrdup
t->buffer = strdup(file_name);
Otherwise, you need to allocate memory then copy separately
t->buffer = malloc(strlen(file_name)+1); strcpy(t->buffer, file_name);
In either case, you'll need to
free(t->buffer)
when you free memory for eachnode
相关问答
更多-
AVL树与平衡树(AVL Tree vs Balanced Tree)[2022-05-26]
你可以在内存中拥有平衡的树。 AVL树只是一种平衡树,还有其他树,例如红黑和2-3-4树。 所以,我不知道你在哪里想到平衡树不能存在于内存中,但如果我是你,我会重新思考。 而且,实际上,如果您愿意,也可以将AVL树放在磁盘上。 我怀疑,根据你的评论,你可能想到的是一个BTree,它就像一个二叉树,但每个节点可以拥有多个值,并且有两个以上的子节点,例如: root node -, | V +------+------+------+ | Val1 | Val2 ... -
AVL树比其他树木(如红黑树或2-3棵树或仅仅是普通的BST)有其优点和缺点。 AVL树木: 优点: 简单。 相当容易编码和理解 额外存储:相当小,每个节点2位(存储+ 1,0,-1)。 还有一个技巧,您可以使用您孩子的单个位在每个节点使用1位。 查找常量(查看您最喜欢的分析书:Knuth等)是1.5(所以1.5 log)。 红黑树的常数为2(因此查找时为2 * log(n))。 缺点: 删除是昂贵的。 删除节点仍然是对数,但您可能必须“一直”旋转到树的根。 换句话说,一个更大的常数。 红黑树只需做1次旋转 ...
-
我认为你在这些行中将垃圾字符串插入到数据结构中: for (int i = 1; i <= 10; ++i) t.insert(i+" "); " "的类型是const char * ,当你向它添加一个整数时,你得到另一个与原始指针偏移的const char * 。 因为字符串" "恰好存储在程序中字符串"Printing balance:"之前,所以当您执行该代码时,最终会生成指向"Printing balance:"字符串内各个位置的指针。 要在C ++中正确地将数字转换为字符串,您可以使用s ...
-
这是AVL树吗?(Is this an AVL tree?)[2023-07-19]
不,它不是,因为节点5的子树高度相差超过1。 左子树为空(高度为0),右子树为7-8(因此其高度为2)。 No, it is not, because the subtrees of node 5 differ by more than 1 in height. The left subtree is empty (its height is 0) and the right subtree is 7-8 (so its height is 2). -
AVL树平衡(AVL Tree Balancing)[2022-04-12]
您的代码正在向上攀升。 考虑以下代码: if (this.getLeftChild() != null) { return this.getLeftChild().insert(node); } 并稍微修改它: if (this.getLeftChild() != null) { boolean b = this.getLeftChild().insert(node); // do something here return b; } 当代码从递归调用返回时,每次返回 ... -
strcpy(t->buffer, file_name); 正在写一个未初始化的指针。 您需要为buffer分配内存。 如果您使用的是Posix兼容系统,最简单的方法是使用strdup t->buffer = strdup(file_name); 否则,您需要分配内存然后单独复制 t->buffer = malloc(strlen(file_name)+1); strcpy(t->buffer, file_name); 在任何一种情况下,当你为每个node释放内存时,你需要free(t->buffer ...
-
AVL树插入 - 实现(AVL Tree Insertion - Implementation)[2022-10-03]
轮流: localroot = temp; 您应该通过引用传递参数。 如果没有,实际参数不能改变,你会得到内存泄漏。 AVL :: insertRecursive中的nodeme也是如此。 in rotation: localroot = temp; You should pass parameter by reference. If not, the actual parameter can't be changed and you'll get memory leak. And so does no ... -
AVl树的采用(AVl Tree adoption)[2022-11-22]
简单地说,是的 尝试查找现有实现的源代码,这将在未来帮助您。 Simply put, Yes Try finding the source code for an existing implementation, that should help you in the future. -
销毁整个AVL树(Destroy entire AVL tree)[2023-07-04]
看看这段代码: destroyTree(root); if(root == NULL) std::cout << "destroyed" << std::endl; 可能你的destroyTree函数有这个原型: void destroyTree(nodeType*node); 问题是节点不能更新调用者的内存地址,但只能调用调用者指向的内容。 这意味着root永远不会更新,即它的内容不能更新为NULL。 要做到这一点,你需要一个类似这样的原型: void destroyTree ... -
AVL树插入/删除需要多少次余额检查(How many balance checks are needed in an AVL tree insertion / deletion)[2023-08-19]
插入后,您需要在树的所有方向上更新每个“父”的平衡因子,直到根; 所以这是O(log n)更新的最大值。 但是你只需要进行一次重组就可以将树恢复到它的不变量。 删除后,如插入,您必须在树上一直更新平衡因子; 所以它再次是O(log n)更新。 但是,与insert不同,您可能需要多次重组旋转才能将树恢复为不变量。 http://en.wikipedia.org/wiki/AVL_tree After an insertion, you need to update the balance factor of ...