Ich hatte Probleme mit meiner globalen Variable hoffe, Sie können mir helfen.Globale Variable in JavaScript Ergebnis ist immer undefine
<li>
<a href="<?php echo site_url("adminController/questionAdd/".$row->subjectid); ?>" id="<?php echo $row->subjectid; ?>" class="subject">Add Question</a>
</li>
nun von dieser Linie ich meine ID von click()
in dieser Linie bestehen in Javascript
$(document).ready(function() {
var correctAnswer;
var subId;
$(".subject").click(function() {
subId = ($(this).attr('id')); //passed the id variable into the global variable
alert(subId) // when I alert this it returns the value
});
jetzt habe ich die globale Variable in dieser Zeile die gleiche $ (document) .ready (function()
$('#form-user').submit(function(e){
e.preventDefault();
var me = $(this);
var correct = correctAnswer;
var passedSubId = subId; // passed the global variable to this local variable
console.log(correct); // this is okey
console.log(subId); // this is undefined
});
Ergebnis
i
undefined
hinwollen Haben Sie Ihr Dokument bereit und das Formular korrekt ausgefüllt? –
Vielen Dank für Ihre Antwort. Ja, ich habe es richtig geschlossen. –