gpt4 book ai didi

javascript - 经过一番尝试后禁用单选按钮并分别更改表单

转载 作者:行者123 更新时间:2023-11-28 08:56:38 25 4
gpt4 key购买 nike

<div class="question" id="question_0">
<label>
Something:
<input type="radio" name="radyo" value="1" />
<input type="radio" name="radyo" value="2" />
<input type="radio" name="radyo" value="3" />
<input type="radio" name="radyo" value="4" />
<input type="radio" name="radyo" value="5" />
</label>
</div>
<div class="question" id="question_1">
<label>
FFFF:
<input type="radio" name="radyo" value="1" />
<input type="radio" name="radyo" value="2" />
<input type="radio" name="radyo" value="3" />
<input type="radio" name="radyo" value="4" />
<input type="radio" name="radyo" value="5" />
</label>
</div>
<div class="question" id="question_2">
<label>
asdf:
<input type="radio" name="radyo" value="6" />
<input type="radio" name="radyo" value="2" />
<input type="radio" name="radyo" value="3" />
<input type="radio" name="radyo" value="4" />

</label>
</div>
<button id="next" disabled="disabled">Next</button>

html

.question { display: none; }
#question_0 { display: block; }

CSS

$(document).ready(function() {

/*
* question: What question the user is currently on
* trys: The amount of tries for the CURRENT question
* answers: The answers for each questions. Matches with radio button values
*/
var question = trys = 0,
answers = [1, 6, 2];




// When the user tries to click the next button (only applies when not disabled)
$('#next').click(function() {

// If the next question exists, transition to it
if ($('#question_' + ++question).length) {
$('#next').attr('disabled', 'disabled');
$('#question_' + (question - 1)).fadeOut('fast', function()
{ $('#question_' + ++question).fadeIn('fast'); });
trys = 0;

// Else submit the form
} else alert('submit form'); //$('form').submit(); ???
});




// When the user clicks on a radio button (tries to answer a question)
$('input[type="radio"]').click(function() {

// If the answer does not equal what the user clicked on
if ($(this).val() != answers[question]) {
$('#next').attr('disabled', 'disabled'); //Disable the button
++trys;
if (trys >= 3) { //If the user tried 3 times, they fucked up
$('#question_' + question + ' input').attr('disabled', 'disabled');
alert('you fucked up');
} else alert('wrong'); //If the user still has more tries tell them they're wrong

// Else enable the ability to go to the next question
} else $('#next').removeAttr('disabled');
});

});

JavaScript

嘿我有这个代码。当您单击第一个单选按钮时,您将首先看到某些内容。您可以点击下一步。否则你会看到一些错误消息。三次错误尝试后,表单输入将被禁用。在下一部分中,您将看到另一个单选按钮。但这效果并不好。我以为我在答案数组中有答案,但我不明白为什么它不起作用任何提示?

最佳答案

这里有一些提示:

  1. “下一步”按钮处理程序应在传递到下一个阶段后禁用按钮;
  2. 检查单选按钮值以匹配答案数组中特定阶段的任何值;
  3. 在开始时显示第一阶段;

关于javascript - 经过一番尝试后禁用单选按钮并分别更改表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18397889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com