使用切换/滑动检查/取消检查树 - 一些小的编码问题
虽然这确实使用了我昨天提出的问题中的一些代码(动态检查/取消选中树中的复选框),我觉得这是一个稍微不同的问题,因为我需要添加清除 div
并在树中上下滑动数据。
我已经将昨天学到的内容添加到滑块中,按照此链接 - http://jsfiddle.net/3V4hg / - 但现在我添加了清除 div
如果树的底部没有选择任何选项,树不会一直取消选中到顶部。如果您查看 JSFiddle,如果选中 A 和/或 B 然后取消选中它,则父级和祖级不会自动取消选中。另外,由于某种我还没有弄清楚的原因 - 滑块决定在单击子区域中的复选框时滑动(我还注意到,当大陆切换时,区域区域显示的切换图像会发生变化 -没有尝试解决这个问题,就像添加到 JSFiddle 时注意到的那样)。
我还认为可能有更好的方法来编码切换器/滑块(因为被不止一种切换器使用,但我不确定)。
Whilst this does use some of the code from a question I asked yesterday (Dynamically check / uncheck checkboxes in a tree), I feel that this is a slightly different question as I need to add in clearing divs
and also slide data in the tree up and down.
I've taken what I learnt yesterday and added in a slider as per this link - http://jsfiddle.net/3V4hg/ - but now I've added clearing divs
the tree is not unchecking all the way to the top if the bottom of the tree has no options selected. If you look at the JSFiddle, if you check A and/or B then uncheck it, the parent and grandparent do not uncheck automatically. Also, for some reason that I haven't figured out yet - the slider decides to slide upon clicking the checkbox in the child area (I've also noticed that the toggle image for the region area to display changes when the continent one toggles - haven't tried to solve that as just noticed when adding to JSFiddle).
I'm also thinking that there may be a better way to code the togglers/sliders (since used by more than one kind of toggle, but I'm unsure).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
小提琴:http://jsfiddle.net/3V4hg/2/
我对您的代码进行了一些修改。看看小提琴和注释(在代码和答案的底部):
* 我已将根定义为
元素。应选择第一次出现的
.count(r)y_wrap
元素,这是使用.eq(0)
实现的。您之前的代码包含一些逻辑错误,我也已修复:
$('.toggle img', this)
选择作为子元素的每个![]()
元素.toggle
,这导致树末端的箭头也切换。我使用 event.target 的解决方案更加简洁,并且允许您的示例扩展到更深的树。Fiddle: http://jsfiddle.net/3V4hg/2/
I have applied some modifications to your code. Have a look at the fiddle and comments (at the code, and at the bottom of the answer):
* I have defined the root to be a
<li>
element. The first occurrence of the.count(r)y_wrap
element should be selected, which is achieved using.eq(0)
.Your previous code contained some logical errors, which I have also fixed:
$('.toggle img', this)
selects every<img>
element which is a child of.toggle
, which caused the arrows at the end of the tree to toggle too. My solution usingevent.target
is more neater, and allows your example to be extended to even deeper trees.