Diese Jquery-Anweisung hat 2 Funktionen. Die zweite Funktion isAnswered ist, wo ich die Probleme bekomme. Es sieht irgendwie nicht, dass der Radioknopf angeklickt wird und ich bin mir nicht sicher warum (vielleicht die neuere Version von Jquery?)?Wie können Sie mithilfe von JQuery überprüfen, ob ein Optionsfeld angeklickt wurde?
JQUERY hat zwei Funktionen, aber zweite ist die Frage - immer falsch zurück kommt für show_action:
//[F] button clicked
$(".upload_files").click(function() {
var disabled = $(this).attr("do_disable");
fileClick(audit_instance_id, this, disabled);
});
function fileClick(audit_instance_id, data, disabled) {
var questionID = data.id;
var show_action = isAnswered(questionID);// This always comes back false
if (show_action) {
$('#question_id').val(questionID);
$('#uploaded_files_' + questionID).toggle();
//problem after this
var visible = $('#uploaded_files_' + questionID).is(':visible');
if (visible === true) {
var params = {
'action': 'get_files',
'audit_instance_id': audit_instance_id,
'question_id': questionID
};
$.post('ajax/perform_audit.php', params, function(data) {
displayFiles(data, questionID, audit_instance_id, disabled);
});
show_action = false;
}
} else {
alert("You must answer the Audit question before adding a file.");
}
return false;
}
function isAnswered(comment_id) {
var show_action = false;
$("#options_" + comment_id + " input, #options_" + comment_id + " textarea").each(function(){
//This part seems to be teh issue or the .each above
if($(this).attr("type") == "checkbox" || $(this).attr("type") == "radio"){
if($(this).is(':checked')){
show_action = true;
}
} else if($(this).attr("type") == "text" || $(this).is("textarea")){
if($(this).val()){
show_action = true;
}
}
});
return show_action;
}
HTML:
<a title='Upload file' href='#!' id=$row[questionID] class='btn btn-default btn-xs upload_files'>
<input name="4117" value="1983" id="option_1983" type="radio">
<input name="4117" value="1984" id="option_1984" type="radio">
versuchen in if-Anweisung - $ (this) .prop ('checked') –
Wie konnte ich sehen, wenn type = Radio aktiviert ist? –
'if ($ (this) .prop ('checked')) {show_action = true;}' –