ورود

View Full Version : سوال: چرا این اسکریپت کار نمیکنه؟



se8820726
یک شنبه 05 آذر 1391, 21:14 عصر
سلام دوستان
چرا این اسکریپت کار نمیکنه؟


<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

<script>
$(function(){
var img = new Array();
$("#pics img").each(function(i,imag){
img[i] = new image();
img[i].onload = function() {
$(imag).attr('src',img[i].src);
}
img[i].src = "img/a.png";
});

});
</script>
</head>
<body>
<div id="pics">
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
</div>
</body>
</html>

Variable
دوشنبه 06 آذر 1391, 00:57 صبح
تو قسمت ارگومان های این تابع متغیری رو تعریف کردید که اشتباهه
$("#pics img").each(function(i,imag){
imag

se8820726
دوشنبه 06 آذر 1391, 02:04 صبح
داداش اصلا اون متغیر و پاکش میکنم و اسکریپتو اینجوری مینیویسم:

<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

<script>
$(function(){
var img = new Array();
$("#pics img").each(function(i){
img[i] = new image();
img[i].onload = function() {
alert('image loaded');
}
img[i].src = "img/a.png";
});

});
</script>
</head>
<body>
<div id="pics">
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
<img class='pic' src='img/preload.gif' alt=''>
</div>
</body>
</html>


اما بازم جواب نمیده!!

se8820726
دوشنبه 06 آذر 1391, 16:19 عصر
لطفا دوستان راهنمایی کنند

se8820726
دوشنبه 06 آذر 1391, 23:51 عصر
سلام دوستان مشکل حل شد
فقط سر یه غلط املایی ریز بود. در واقع حرف i کلمه image رو باید بزرگ مینوشتم.
یعنی به جای این دستور:

img[i] = new image();

باید اینو مینوشتم:

img[i] = new Image();