הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   בעיה עם setTimeout (https://hosts.co.il/forums/showthread.php?t=76657)

Gal Shafrir 15-07-09 23:51

בעיה עם setTimeout
 
היי אנשים.

יש לי בעיה עם jQuery/setTimeout. אני חושב שזה עם הjQuery
כי כשעשיתי שcloseMsg תציג alert הsetTimeout עבד מעולה.

הקוד עובד בסדר, אין בו שגיאות למי שתוהה (חוץ מסגירת ההודעה).
פשוט ברגע שאני כותב בsetTimeout דיליי שהוא יותר גדול מ900 זה לא עובד.

הנה הפונקצייה:
PHP קוד:

function addSelectedItems(formcat) {

    var 
products = [];
    var 
count 0;
    var 
countAdd 0;
    var 
msg "";

    
// get the products number
    
var 0;
    $(
"input.amount").each(function() {
        
j++;
        
count++;

        
amount = $('#amount' j).val();
        if (
amount 0)
            
countAdd++;

    });


    for (var 
1<= counti++) {

        if (
== 1) {

            $(
"#AddToShoppingCart").fadeIn("slow");
            $(
"#ShoppingCartMsg").html("the products were added to your shopping cart");

        } else {

            if ((
1) == countAdd) {
                
setTimeout('closeMsg();',1000);
            }

        }
    
        var 
amount = $('#amount' i).val();
        if (
amount 0) {

        
            var 
colorObj document.getElementById('color-' i);
            if (
colorObj) {
                
color colorObj.options[colorObj.selectedIndex].value;
            } else {
                
color "default";
            }

            var 
catalog_number = $('#catalog_number' i).val();

            var 
time = new Date().getTime();
            var 
serverPage 'index.php?module=cart&advanced=true&ajax=true&act=addProduct&catalog_number=' catalog_number '&amount=' amount '&color=' color '&time=' time;

            $.
get(serverPage);

            
MiniCart(false); // updates MiniCart

            
document.getElementById('items').innerHTML getItems();

            var 
mktime = new Date().getTime();
            if (
cat != "") {

                var 
loadPage 'index.php?module=catalog&act=categories&id=' cat '&ajax=true&time=' mktime;

                $.
get(loadPage, function(server) {
                    $(
"#products-list").html(server);
                })

            } else {

                var 
page document.getElementById("page").value;
                
                $.
get(page+"&time="+mktime, function(server) {
                    $(
"#products-list").html(server);
                });

            }

        }
    }



הפונקצייה closeMsg:
PHP קוד:

function closeMsg() {
    $(
"#ShoppingCartMsg").html("TESTING");



תודה לעוזרים ;)

AlmogBaku 16-07-09 07:44

מוזר. אתה אומר שאלרט פשוט עובד לך שם?[דרך קריאה מטייםאווט] ותן לינק.


ותנסה לכתוב:
PHP קוד:

setTimeout('closeMsg',1000); 


Gal Shafrir 16-07-09 10:23

ניסיתי, הfadeIn עובד, אבל פשוט נשאר (הhtml ב-closeMsg פשוט לא עובד).

Gal Shafrir 17-07-09 22:19

מצטער על הדאבל פוסט.
הנה הפתרון:

יצירת השהייה של 3 שניות בעזרה אנימציה (השקיפות לא משתנה, ולכן
בעצם לא קורה כלום בזמן הזה), לאחר מכן fadeOut רגיל.

PHP קוד:

$("#selector").fadeIn("slow");

$(
"#selector").animate({ opacity1.0 }, 3000);

$(
"#selector").fadeOut("slow"); 


תודה לאלמוג על העזרה.


כל הזמנים הם GMT +2. הזמן כעת הוא 22:01.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ