我有一个问题。 jQuery('#FinishTest').click()
有效,但当您选择所有答案时它会停止。该错误不会出现在控制台中。
我的代码
jQuery('#FinishTest').click(function() {
var names = {};
jQuery(':radio').each(function() {
names[jQuery(this).attr('name')] = true;
});
var count = 0;
jQuery.each(names, function() {
count++;
});
if (jQuery(':radio:checked').length > 3) {
if (jQuery(':radio:checked').length < count) {
if (confirm("Henüz cevaplanmamış sorularınız var. Testi bitirmek istediğinizden eminmisiniz ?")) {
finishtest();
} else {
jQuery('#FinishTest').bind('click');
return;
}
}
} else {
alert('Testi bitirebilmek için en az 2 soru cevaplamalısınız.');
}
});
最佳答案
发生这种情况是因为您的代码中存在以下情况:
if( jQuery(':radio:checked').length < count )
当您选择所有答案时,您将得到 jQuery(':radio:checked').length
等于六 6
和 count
变量值也将是 6
所以条件永远不会计算为 true。
尝试添加等于您的条件=
所以它将低于或等于 <=
:
if( jQuery(':radio:checked').length <= count ){
//Your logic here
}
希望这有帮助。
更改并解决问题。
if (jQuery(':radio:checked').length > 3) {
if (jQuery(':radio:checked').length < count) {
if (confirm("Henüz cevaplanmamış sorularınız var. Testi bitirmek istediğinizden eminmisiniz ?")) {
finishtest();
}
} else {
finishtest();
}
} else {
alert('Testi bitirebilmek için en az 2 soru cevaplamalısınız.');
}
关于javascript - jQuery 点击事件停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47291420/