Ich erwartete, dass der Code unten "0" und "1" warnt, aber es warnt zweimal "2". Ich verstehe den Grund nicht. Ich weiß nicht, ob es ein Problem von jQuery ist. Bitte helfen Sie mir auch Titel und Tags dieses Beitrags zu bearbeiten, wenn sie ungenau sind.Umfang der Variablen in JavaScript Callback-Funktionen
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
for (var i=0; i<2; i++) {
$.get('http://www.google.com/', function() {
alert(i);
});
}
});
</script>
</head>
<body>
</body>
</html>
@chaos: rechts unter "Macht HTML nicht mit regex", denke ich. ;) – Tomalak
* (nichts für ungut) * [JavaScript Closures for Dummies] (http://blog.morrisjohns.com/javascript_closures_for_dummies.html) Beispiel 5 –
Es ist schwer, nur einen aus der Nähe auszuwählen: http://stackoverflow.com/ Fragen/1734749/ http: // Stapelüberlauf.com/Fragen/643.542/ http://stackoverflow.com/questions/1582634/ http://stackoverflow.com/questions/1331769/ http://stackoverflow.com/questions/1552941/ http://stackoverflow.com/questions/750486/ http://stackoverflow.com/questions/933343/ http://stackoverflow.com/questions/1579978/ http://stackoverflow.com/ Fragen/1413916/ http://StackOverflow.com/Questions/2808471/ – CMS