希望在这里的任何帮助新手。我有一个简单的if/else if语句,出于某种原因只能达到第二个条件,即使第三个条件满足。我已经尝试添加到最后,尝试几乎一切,但仍然没有。我知道这不起作用,因为我添加了警报触发器,并且不管它从未达到第三个条件。我在这里错过了什么?我环顾四周,所以我很抱歉,如果我在这里击败死马,但我找不到解决方案。我应该注意到,我试图通过选择下拉框来改变条件。谢谢!!!如果其他语句不按预期工作
我的代码:
$('#table_two select:eq(6)').change(function(e){
var allDiv = $('#table_two,#table_three,#table_four');
var parBoxOne = $('#par_one').val();
var totalOne = 1 - parBoxOne;
var totalTwo = 2 - parBoxOne;
if ($(this).val() == "made_shot"){
$(allDiv).hide();
$('#score_one').val(totalOne);
$('#score_total').val($('.score_input').val());
alert('ACE!!');
}
else if ($(this).val() == 'green', 'trees', 'fairway', 'rough', 'sand'){
$('#score_one').val(totalOne);
$('#score_total').val($('.score_input').val());
$('#table_two').hide();
$('#butt_two').html('Show stroke');
alert('triggered two');
}
else if ($(this).val() == 'other', 'penalty_water', 'penalty_ob', 'penalty_sand'){
$('#score_one').val(totalTwo);
$('#score_total').val($('.score_input').val());
$('#table_two').hide();
alert('triggered three');
}
});
+1。其他答案解释了为什么原文不起作用,但当所有条件都测试相同的值时,转换语句更有意义。 – nnnnnn 2012-07-20 01:24:53
@nnnnnn谢谢你,其他的答案已经解释了他会出错的地方。 – sabithpocker 2012-07-20 01:27:17
它的工作原理!感谢您花时间向像我这样的新手解释这一点。我很感激! – beatmusic67 2012-07-20 19:12:44