Как при нажатии на один чекбокс скрывать блок, а на другой показывать..
Всем привет, не могу найти решение данного вопроса. Теперь подробнее!
Есть див с тремя чекбоксами(radio): Код:
<div class="radio">Буду признателен за помощь. |
Цитата:
Цитата:
|
Цитата:
|
Tiesto,
var $div=$('#hidden_div');//«hidden_div» - ID скрытого div'а
$('#optradio,#optradio2,#optradio3').change(function(){
var $t=$(this);
if($t.is(':checked'))
$div[$t.attr('id').substr(-1)!=3?'show':'hide']();
});
|
Tiesto,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">.slider{
display: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
$('[name="1"]').on("click", function() {
$(".slider").toggle(this.id != "optradio")
})
});
</script>
</head>
<body>
<div class="radio">
<label>
<input type="radio" name="1" id="optradio" value="" checked="checked">
Нет
</label>
<label>
<input type="radio" name="1" id="optradio2" value="">
Да
</label>
<br>
<label>
<input type="radio" name="1" id="optradio3" value="">
Да, но..
</label>
</div>
<div class="slider">slider</div>
</body>
</html>
|
Вариант без id с value
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">.slider{
display: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
$('[name="1"]').on("click", function() {
$(".slider").css('display',this.value)
})
});
</script>
</head>
<body>
<div class="radio">
<label>
<input type="radio" name="1" value="none" checked="checked">
Нет
</label>
<label>
<input type="radio" name="1" value="block">
Да
</label>
<br>
<label>
<input type="radio" name="1" value="block">
Да, но..
</label>
</div>
<div class="slider">slider</div>
</body>
</html>
|
| Часовой пояс GMT +3, время: 19:06. |