jQuery toggle() issue
jQuery toggle() issue
我使用的是本次讨论中的脚本:https://wordpress.stackexchange.com/a/14711/14649
它工作得很好,但当我选择不同的无线电输入时,原始框不会关闭(坏),但新框会出现(好)。我添加的任何其他框都会发生这种情况。
jQuery不是我喜欢的,我一直在四处研究,但运气不好!这是我的代码:
<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#feature_box').hide();
$('#standard_lead').hide();
// one box
$('#value_feature_box').is(':checked') ? $("#feature_box").show() : $("#feature_box").hide();
$('#value_feature_box').click(function() {
$("#feature_box").toggle(this.checked);
});
// second box
$('#value_standard_lead').is(':checked') ? $("#standard_lead").show() : $("#standard_lead").hide();
$('#value_standard_lead').click(function() {
$("#standard_lead").toggle(this.checked);
});
});
</script>
谢谢你看!
另一个盒子之所以没有消失,是因为你没有告诉它!
$('#value_feature_box').click(function() {
$("#feature_box").toggle(this.checked);
});
这表示在单击#value_feature_box时切换#feature_box的可见性。如果#value_feature_box不是复选框,则将内部代码更改为$("#feature_box").toggle();
。如果你想让一些东西也消失,那么告诉它:
$('#value_feature_box').click(function() {
$("#feature_box").toggle();
$("#standard_lead").toggle();
});
toggle()括号内的值告诉它出现或消失(true或false)。
点击时只切换一个框-需要同时切换两个框,请参阅jsFiddle:
- http://jsfiddle.net/Gr8Jq/
有了这个(对于另一个盒子也是类似的):
$('#value_feature_box').click(function() {
$("#feature_box").toggle(this.checked);
});
您基本上是在说-单击时(因此this.checked
将始终为true),切换元素。来自文档:
- http://api.jquery.com/toggle/
您使用的toggle版本具有showOrHide参数,并且始终传递true,因此始终显示并仅显示单击的框。
相关文章:
- issue with FB.Event.subscribe
- jQuery/Javascript.toggleClass/.classList.toggle的特殊行为
- 使用Jquery Issue垂直重新排序Divs
- 创建了一个选项卡,但点击时不会起作用-jQuery issue/newbie
- jQuery find() Issue
- $route.reload(); Issue
- PHP json_encode issue
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- Three.js issue creating meshes outside of loader's load(
- Jquery :gt(value) issue
- Toggle Javascript
- pickaday maxDate issue
- Stage.load(json) Issue..Kinetic.js
- 如何分解jQuery"toggle”;函数转换为separate“;显示“;以及“;隐藏“;功能
- Mootools Selector issue
- Java 8 Update 91 Issue
- JS parseInt() issue
- Bootstrap javascript wordpress issue data-toggle="colla
- jQuery toggle() issue
- jQuery .toggle() child issue