检查无线电时删除类

时间:2017-12-24 12:46:01

标签: javascript jquery radio-button

如果选中收音机,我会有一个按钮簿,按钮簿中禁用的所有课程都将被删除,如果只检查了那个,则按钮簿仍然被禁用。

我试图使其功能发挥作用但不起作用。

$(document).ready(function() {
  var departInput = $('#flightResultOneway input:radio');
  var returnInput = $('#flightResultReturn input:radio');

  $(departInput).click(function() {
    $('#flightResultOneway input:not(:checked)').parent().addClass('hide');
    $('#flightResultOneway input:checked').parent().removeClass('hide');
  });

  $(returnInput).click(function() {
    $('#flightResultReturn input:not(:checked)').parent().addClass('hide');
    $('#flightResultReturn input:checked').parent().removeClass('hide');
  });
});

// BUTTON BOOK
if($('#flightResultOneway input:checked')){
	$('#book').removeClass('disabled');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="flightResultOneway" class="list-result">
<h1>Depart</h1>
  <div class="result-list">
    <label class="item">
      <input type="radio" name="depart">lion
    </label>
    <label class="item">
      <input type="radio" name="depart">citi
    </label>
  </div>
</div>
<div id="flightResultReturn" class="list-result">
<h1>Return</h1>
  <div class="result-list">
    <label class="item">
      <input type="radio" name="return">citi
    </label>
    <label class="item">
      <input type="radio" name="return">lion
    </label>
  </div>
</div>

<div class="next-book">
  <a href="#" id="book" class="btn btn-primary disabled">book</a>
</div>

1 个答案:

答案 0 :(得分:0)

可能这就是你想要的......

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="flightResultOneway" class="list-result">
<h1>Depart</h1>
  <div class="result-list">
    <label class="item">
      <input type="radio" name="depart">lion
    </label>
    <label class="item">
      <input type="radio" name="depart">citi
    </label>
  </div>
</div>
<div id="flightResultReturn" class="list-result">
<h1>Return</h1>
  <div class="result-list">
    <label class="item">
      <input type="radio" name="return">citi
    </label>
    <label class="item">
      <input type="radio" name="return">lion
    </label>
  </div>
</div>

<div class="next-book">
  <a href="#" id="book" class="btn btn-primary disabled">book</a>
</div>

和你的HTML

def scores_to_rating(score1,score2,score3,score4,score5):
    score1 = convert_to_numeric(score1)
    score2 = convert_to_numeric(score2)
    score3 = convert_to_numeric(score3)
    score4 = convert_to_numeric(score4)
    score5 = convert_to_numeric(score5)
    min_score = min(score1, score2, score3, score4, score5)
    max_score = max(score1, score2, score3, score4, score5)
    sum_of_all_five_scores = score1 + score2 + score3 + score4 + score5
    sum_of_three_middle_scores = sum_of_all_five_scores - min_score - max_score
    average_score =  sum_of_three_middle_scores/3
    rating = average_score
    return rating
    print(scores_to_rating(10,20,30,40,50))