javascript 使用 jQuery 和 jQueryUI 显示/隐藏 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13138525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show/Hide div using jQuery and jQueryUI
提问by xgstr
I'm very new to this and have limited knowledge (all self taught over the last few weeks). I have tried a number of solutions from similar questions that others have asked, and none seem to work for me.
我对此很陌生,知识有限(过去几周都是自学的)。我已经从其他人提出的类似问题中尝试了许多解决方案,但似乎没有一个对我有用。
I am trying to set the 'date_range' div to only be visible when the 'range' filter is selected. I'm using jQuery 1.8.2 and jQueryUI 1.9 (set with $.noConflict(); ).
我试图将 'date_range' div 设置为仅在选择了 'range' 过滤器时可见。我正在使用 jQuery 1.8.2 和 jQueryUI 1.9(用 $.noConflict(); 设置)。
My code is below (please be kind, I know I'm not very good at this), any help is appreciated.
我的代码如下(请善待,我知道我不太擅长这个),任何帮助表示赞赏。
<script>
$('#filters').is(function() {
if ($('#range').attr('checked')) {
$('#date_range').show();
} else {
$('#date_range').hide();
}
});
</script>
<div>
<form align="center" id="filters">
<input type="radio" id="last24" name="filter_radio" checked="checked"/><label for="last24">Last 24hrs</label>
<input type="radio" id="WTD" name="filter_radio" /><label for="WTD">WTD</label>
<input type="radio" id="last_week" name="filter_radio" /><label for="last_week">Last Week</label>
<input type="radio" id="range" name="filter_radio" /><label for="range">Range</label>
<div id="date_range">
<br />
<label for="from">From: </label><input type="text" id="from" name="from"/>
<label for="to">To: </label><input type="text" id="to" name="to" />
</div>
</form>
</div>
回答by Yograj Gupta
回答by Ankush Kalia
Try this code:-
试试这个代码:-
This is jquery to hide and show:-
这是用于隐藏和显示的 jquery:-
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js" ></script>
<script>
function asfd(str)
{
if(str==true)
{
jQuery('div#renew').show();
}
else
{
jQuery('div#renew').hide();
}
}
</script>
This is where Jquery function called :-
这是 Jquery 函数调用的地方:-
<input type="checkbox" autocomplete="off" onchange="asfd(this.checked);"/>
This is the div which will hide or to show:-
这是将隐藏或显示的 div:-
<div id="renew" style="display: none ;">
........Content.........
</div>
回答by chridam
You could try this
你可以试试这个
Markup:
标记:
<label><input id="last24" type="radio" name="filter_radio" value="1" />Last 24hrs</label>
<label><input id="WTD" type="radio" name="filter_radio" value="2" />WTD</label>
<label><input id="last_week" type="radio" name="filter_radio" value="3" />Last Week</label>
<label><input id="range" type="radio" name="filter_radio" value="4" />Range</label>
<div id="filter_radio-4" class="toHide" style="display:none">
<br />
<label for="from">From: </label><input type="text" id="from" name="from"/>
<label for="to">To: </label><input type="text" id="to" name="to" />
</div>
Javascript:
Javascript:
$(function() {
$("[name=filter_radio]").click(function(){
$('.toHide').hide();
$("#filter_radio-"+$(this).val()).show('slow');
});
});?
回答by Milli
You can achieve it with this
你可以用这个来实现它
$('#date_range').hide();
$('[name=filter_radio]').on('click', function(){
if($('#range').is(':checked')){
$('#date_range').show();
} else {
$('#date_range').hide();
}
});
Hope its simple and clear ..
希望它简单明了..