我对.JS很陌生,而且我使用的代码不是我最初编写的。我需要得到一些单选按钮的价值,一旦条件选择已经作出。
有条件的部分涉及运输的需要。如果用户需要交通,一组新的单选按钮将显示巴士路线选项。这些是我需要由表单返回的值。
HTML:
<fieldset>
<legend>Transportation Registration</legend>
<div class="col3">
<div class="checklabel">Transportation needs</div>
<ul class="checkwrap">
<li>
<input name="transportation" type="radio" id="transportation-none" value="None" checked="checked" data-price="0" data-deposit="0" />
<label for="transportation-none">None</label>
</li>
<li>
<input name="transportation" type="radio" id="transportation-am_only" value="AM Only" data-price="60" data-deposit="50" />
<label for="transportation-am_only">AM Only</label>
</li>
<li>
<input name="transportation" type="radio" id="transportation-pm_only" value="PM Only" data-price="60" data-deposit="50" />
<label for="transportation-pm_only">PM Only</label>
</li>
<li>
<input name="transportation" type="radio" id="transportation-round_trip" value="Both AM & PM" data-price="100" data-deposit="50" />
<label for="transportation-round_trip">Round-Trip</label>
</li>
</ul>
</div>
<div align="center"><p><strong>One-Way (AM or PM): $60/week | Round-Trip: $100/week</strong></p></div>
<div>
<div class="checklabel">Bus Route 1:</div>
<ul class="checkwrap">
<li><input name="busroute" type="radio" id="bus_1" value="Bus 1" class="required" /><label for="bus_1">Bus 1</label></li>
<li><input name="busroute" type="radio" id="bus_2" value="Bus 2" class="required" /><label for="bus_2">Bus 2</label></li>
<li><input name="busroute" type="radio" id="bus_3" value="Bus 3" class="required" /><label for="bus_3">Bus 3</label></li>
<li><input name="busroute" type="radio" id="bus_4" value="Bus 4" class="required" /><label for="bus_4">Bus 4</label></li>
</ul>
</div>
与(不完全) .JS:
function transportation() {
if($('#transportation-none').is(':checked')) {
$('[name=busroute]')
.removeClass("required")
.val('')
.closest('div')
.hide();
} else {
$('[name=busroute]')
.addClass("required")
.closest('div')
.show();
}
}我希望这是合理的。这个页面包含了更多的函数,但是我想我是在调用需要修复的部分。我可能需要提供更多的代码才能得到答案。
发布于 2014-03-22 00:25:04
你已经定义了你的函数,但是,根据你所展示的,你从来没有叫它。可以使用jQuery将此函数调用绑定到传输无线电输入中的任何更改事件:
$('input[name="transportation"]').on('change', transportation);https://stackoverflow.com/questions/22568935
复制相似问题