我有一个应用程序,当一个特定的单选按钮被选中时显示一个div,然后当单选按钮未被选择时隐藏该div。问题是,附加到单选按钮的更改事件只有在单选按钮被选中时才会被调用,而不是当选中另一个(取消选中前一个)时。我当前的代码如下:
<form name="newreport" action="#buildurl('report.filters')#" method="post"> <dl class="oneColumn"> <dt class="first"><label for="txt_name">Name</label></dt> <dd><input type="text" name="name" id="txt_name" class="text" /></dd> <dt><strong>Type</strong></dt> <dt><input type="radio" name="type" id="rdo_list" value="list" checked="checked" /><label for="rdo_type" style="display:inline;">List</label></dt> <dd>List a group of records</dd> <dt><input type="radio" name="type" id="rdo_fields" value="fields" /><label for="rdo_fields" style="display:inline;">Field Breakdown</label></dt> <dd>Breaks down distinct field values for comparison</dd> <dt><input type="radio" name="type" id="rdo_history" value="history" /><label for="rdo_history" style="display:inline;">Historical Comparison</label></dt> <dd>Provides record changes over a group of years for growth comparisons</dd> <dt><input type="radio" name="type" id="rdo_breakdown" value="breakdown" /><label for="rdo_breakdown" style="display:inline;">Student Breakdown</label></dt> <dd>Breaks down students by school,district or grade</dd> <div class="reportyear"> <dt><label for="txt_year">Year to Report</label></dt> <dd><input type="text" name="year" id="txt_year" class="text" value="#year(Rc.yearstart)#" /></dd> </div> <div class="date-spans" style="display:none;"> <dt><label for="txt_yearstart">Year Start</label></dt> <dd><input type="text" name="yearstart" id="txt_yearstart" class="text" value="#evaluate(year(Rc.yearstart)-5)#" /></dd> <dt><label for="txt_yearend">Year End</label></dt> <dd><input type="text" name="yearend" id="txt_yearend" class="text" value="#year(Rc.yearstart)#" /></dd> </div> </dl> </form> <script type="text/javascript"> $(function(){ $('##rdo_history').change(function(e){ var isChecked = $(this).attr(checked); var $datespan = $('form .date-spans'); var $year = $('form .reportyear'); if(isChecked){ $year.css({display:'none'}); $datespan.fadeIn('fast'); }else{ $datespan.css({display:'none'}); $year.fadeIn('fast'); } }); }); </script>
它看起来像一个非常简单的脚本,但事件只能在检查事件,而不是uncheck事件。任何人都可以告诉我为什么?