Кнопка radio - работа по клику и по умолчанию.
Добрый день! Как сделать так, чтобы радио кнопка работала по клику и по дефолту.
Пример: По клику работает, не нужные поля прячутся нужные показываются, в зависимости от кнопки, теперь хочу сделать, чтобы по умолчанию было выбрано "физическое лицо" прятались сразу не нужные поля и показывались нужные. $(function(){ $("input:radio[name=test]").click(function(){ var value = $(this).attr("value"); switch (value){ case 'физическое лицо': testik11(value) break case 'юридическое лицо': testik12(value) break default: alert('Вторая') } }); function testik11(value){ $("#text_log").html(value+ "<b>Ok</b>"); $(".next").show(); $("#InpFrm9").hide(); $("#InpFrm9text").hide(); $("#InpFrm10").hide(); $("#InpFrm10text").hide(); $("#InpFrm11").hide(); $("#InpFrm11text").hide(); $("#InpFrm12").hide(); $("#InpFrm12text").hide(); $("#radio22").hide(); $("#InpFrm22radio").hide(); } function testik12(value){ $("#text_log").html(value+ "<b>Ok</b>"); $(".next").show(); $("#InpFrm9").show(); $("#InpFrm9text").show(); $("#InpFrm10").show(); $("#InpFrm10text").show(); $("#InpFrm11").show(); $("#InpFrm11text").show(); $("#InpFrm12").show(); $("#InpFrm12text").show(); $("#radio22").show(); $("#InpFrm22radio").show(); } }); <fieldset> <legend>Способ получения</legend> <input type="radio" class="face" id="radio1" name="test" value="физическое лицо" title="физическое лицо" ><label for="radio1">физическое лицо</label> <input type="radio" class="face" id="radio2" name="test" value="юридическое лицо" title="юридическое лицо"><label for="radio2">юридическое лицо</label> <!--<div id="text_log"></div>--> <hr> |
A, вот и решение. Может быть кому-то пригодится.
$(document).ready(function(){ // Зададим обработчик вызывающийся при нажатии на кнопку с id=but1 $("input:radio#radio1").click(function(){ var value = $(this).attr("value"); $("#text_log").html(value+ "<b>Ok</b>"); $("#InpFrm9").hide(); $("#InpFrm9text").hide(); $("#InpFrm10").hide(); $("#InpFrm10text").hide(); $("#InpFrm11").hide(); $("#InpFrm11text").hide(); $("#InpFrm12").hide(); $("#InpFrm12text").hide(); $("#radio22").hide(); $("#InpFrm22radio").hide(); }); // Зададим обработчик вызывающийся при нажатии на кнопку с id=but1 $("input:radio#radio2").click(function(){ var value = $(this).attr("value"); $("#text_log").html(value+ "<b>Ok</b>"); $("#InpFrm9").show(); $("#InpFrm9text").show(); $("#InpFrm10").show(); $("#InpFrm10text").show(); $("#InpFrm11").show(); $("#InpFrm11text").show(); $("#InpFrm12").show(); $("#InpFrm12text").show(); $("#radio22").show(); $("#InpFrm22radio").show(); }); // Вызовем привязанный ранее обработчик $("input:radio#radio1").click(); }); |
Часовой пояс GMT +3, время: 15:58. |