0

我有一个处理一些 PHP 代码的 JavaScript,如下所示:

$(function(){
    $("#hosted_prev_no").change(function(){ 
        $("#attend").show();
        $("#eligible").hide();
    });
    $("#hosted_prev_yes").change(function(){
        $("#attend").hide();
        $("#eligible").show();
    });
    $("#attend_prev_yes").change(function(){
        $("#eligible").show();
    });
    $("#attend_prev_yes").change(function(){
        $("#eligible").hide();    
    });

php代码如下:

  <div class="full row column">
    <label id="hosted_prev_label" for="hosted_prev" class="required">Have you hosted a Road Scholar program for Stetson University in the past?</label>
    <label id="hosted_prev_yes_label" for="hosted_prev_yes">Yes</label>
    <input id="hosted_prev_yes" name="hosted_prev" type="radio" value="Yes" />
    <label id="hosted_prev_no_label" for="hosted_prev_no">No</label>
    <input id="hosted_prev_no" name="hosted_prev" type="radio" value="No" /><br />
    <div id="attend" class="hidden">
      <label id="atend_prev_label" for="atend_prev" class="required">Have you attended at least one Stetson Road Scholar program in the past?</label>
      <label id="attend_prev_yes_label" for="attend_prev_yes">Yes</label>
      <input id="attend_prev_yes" name="attend_prev" type="radio" value="Yes" />
      <label id="attend_prev_no_label" for="hosted_prev_no">No</label>
      <input id="attend_prev_no" name="attend_prev" type="radio" value="No" /><br />
    </div>
    <div id="ineligible" class="hidden">
      <p>All hosts are required to attend at least one Stetson University Road Scholar program before they may host p program. You may apply again once you have attended a Stetson University Road Scholar program. Thank you for your interest.</p>
    </div>
  </div>
  <div id="eligible" class="full row column hidden">
    <h2>Cohost Information</h2>
    <label id="is_cohost_label" for="is_cohost" class="required">Will you be hosting with anyone?</label>
    <label id="is_cohost_yes_label" for="is_cohost_yes">Yes</label>
    <input id="is_cohost_yes" name="is_cohost" type="radio" value="Yes" />
    <label id="is_cohost_no_label" for="is_cohost_no">No</label>
    <input id="is_cohost_no" name="is_cohost" type="radio" value="No" /><br />
  </div>

问题是第二个收音机没有显示“ eligible” div。你怎么知道哪个变化函数在这里有优先权?

4

1 回答 1

0

您绑定相同的元素两次:

$("#attend_prev_yes").change(function(){
    $("#eligible").show();
});
$("#attend_prev_yes").change(function(){
    $("#eligible").hide();    
});

我认为你需要的是:

$("#attend_prev_yes").change(function(){
    $("#eligible").show();
});
$("#attend_prev_no").change(function(){
    $("#eligible").hide();    
});
于 2013-05-07T12:48:54.973 回答