大佬教程收集整理的这篇文章主要介绍了jquery – 当图例元素点击时,将会将其缩小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$('legend.togvis').click(function() { $(this).siblings().toggle(); return false; });
除非fieldset包含文本节点,否则它的效果非常好.
<fieldset><legend class='togvis'>Click Me</legend> <p>I toggle when the legend is clicked.</p> But I'm a recalcitrant text node and refuse to toggle. </fieldset>
为了切换文本节点,我也尝试过:
$('legend.togvis').click(function() { $(this).parent().contents().not('legend').toggle(); return false; });
$('legend.togvis').click(function() { $(this).parent().contents(":not(legend)").toggle(); return false; });
这会抛出错误
message: 'style.display' is null or not an object Line: 5557 Char: 3 Code: 0 URI: http://code.jquery.com/jquery-1.4.4.js
关于如何获取字段集(减去图例)的全部内容以在点击图例时切换的任何想法?
ETA解决方案,非常感谢Eibx
$('legend.togvis').click(function() { $(this).parent().contents().filter( function() { return this.nodeType == 3; }).wrap('<span></span>');//wrap any stray text nodes $(this).siblings().toggle(); });@H_944_26@
以下代码将所有内容都包装成div,并将您的图例移动到与div相同的级别,并在点击图例时使div显示/隐藏.
$("fieldset legend").click(function() { if ($(this).parent().children().length == 2) $(this).parent().find("div").toggle(); else { $(this).parent().wrapInner("<div>"); $(this).appendTo($(this).parent().parent()); $(this).parent().find("div").toggle(); } });
>代码:http://jsbin.com/eleva3/edit
>预览:http://jsbin.com/eleva3
以上是大佬教程为你收集整理的jquery – 当图例元素点击时,将会将其缩小全部内容,希望文章能够帮你解决jquery – 当图例元素点击时,将会将其缩小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。