Я пытаюсь вызвать 3 разных окна оповещения в зависимости от конкретных условий.В моем операторе if-else у меня есть следующее (только фрагмент):
$('input[name=answer]').on('change', function() {
if ((practice_trials.stimulus == "images/some-bias1.png" || practice_trials.stimulus == "images/some-unbias1.png" || practice_trials.stimulus == "images/all-unbias3.png") && $('input[id=no]:radio').is(':checked')){
window.alert("Oops, you should have taken the box!");
} else if (practice_trials.stimulus == 'images/all-false3.png' && $('input[id=yes]:radio').is(':checked')){
window.alert("Oops, you should have left the box behind!");
} else {
window.alert("You've got it right!");
}
JQuery указывает на выбор переключателя, в то время как JS ссылается на словарь, хранящийся в отдельном файле с именем practice_trials.js .Словарь имеет следующую структуру:
var practice_trials = [
{question: "Should you bring Johnny this box or not?",
QUD: "Johnny says: 'I want you to bring me the box where ...",
sentence: "some | of the | black marbles | are | inside | the case.'",
option1: "Bring it",
option2: "Leave it",
stimulus: "images/some-bias1.png",
helpText: "Press the SPACE bar to reveal the words"},
HTML имеет следующую структуру:
<p class="answer-container nodisplay">
<label for="yes" class="button-answer">{{option1}}</label>
<input type="radio" name="answer" id="yes"
value={{option1}} />
<input type="radio" name="answer" id="no" value={{option2}} />
<label for="no" class="button-answer">{{option2}}</label>
</p>
До сих пор, независимо от условий, я всегда получал последнее предупреждение («Вы»мы правильно поняли! ").